Jump to content
Killersites Forums

How do I find line 10 to fix this php error


Recommended Posts

"Parse error: syntax error, unexpected '.' in /homepages/21/d176117763/htdocs/register.php on line 10"

 

this is the error I get.

 

My register.php is pasted below, I assume I must remove '.' somewhere? help appreciated. :(

 

<?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

. . $sql = mysql_query (*INSERT INTO users (

. . . . user_id,username,user_regdate)

. . . . Values (

. . . . '0','".$username."','".$password."','".time()."')

. . . . ");

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

~

Edited by billperrotta
Link to post
Share on other sites

My edits...

 

-- removed the "*" before INSERT. I'm assuming that was a typo

-- added a closing "}" just before the closing "?>"

-- changing the SQL query to this:

 

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)
           values (0,$username,$password,time())");

 

You added a space between "mysql_query" and the opening "(" -- I'm not sure if that would have made a difference, but just in case... You also forgot the opening quote in front of "INSERT", and had a lot of unnecessary quotes.

 

This query won't work though... You are telling the server that you are going to insert three fields into the users table (user_id, username, user_regdate) yet you are providing it with four fields worth of data (0,$username,$password,time()). I'm not sure what that needs to be corrected to, since I don't know what data you're trying to add and I don't know the structure of your table.

 

One other comment... is your "user_id" column in the database set to auto-increment? If so, why are you setting that field in your SQL query?

 

What editor are you using to write PHP? You probably should be using a text editor that includes syntax highlighting. Just putting your code into my editor showed me that there was an issue because the syntax highlighting was off. It won't necessarily show you exactly where the error is, but sometimes gives you an idea of where to start looking.

Link to post
Share on other sites
My edits...

 

-- removed the "*" before INSERT. I'm assuming that was a typo

-- added a closing "}" just before the closing "?>"

-- changing the SQL query to this:

 

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)
           values (0,$username,$password,time())");

 

You added a space between "mysql_query" and the opening "(" -- I'm not sure if that would have made a difference, but just in case... You also forgot the opening quote in front of "INSERT", and had a lot of unnecessary quotes.

 

This query won't work though... You are telling the server that you are going to insert three fields into the users table (user_id, username, user_regdate) yet you are providing it with four fields worth of data (0,$username,$password,time()). I'm not sure what that needs to be corrected to, since I don't know what data you're trying to add and I don't know the structure of your table.

 

One other comment... is your "user_id" column in the database set to auto-increment? If so, why are you setting that field in your SQL query?

 

What editor are you using to write PHP? You probably should be using a text editor that includes syntax highlighting. Just putting your code into my editor showed me that there was an issue because the syntax highlighting was off. It won't necessarily show you exactly where the error is, but sometimes gives you an idea of where to start looking.

 

I was using this tutorial http://www.youtube.com/watch?v=Kl6XcfkKle4. So you can better understand.

 

Just trying to get this logon box created. The editor I was using was vi. seems like through ssh to 1and1 server it doesn't highlight. but locally i think it does on my Suse l aptop. not sure if vim or nano would highlight if i do it sshed into the server.

could also figure out how to ftp up the files if I create them locally. But that requires 2 steps instead of one. What editor are you using that I might install it? :)

Link to post
Share on other sites

Hmm. I'm not all that familiar with Linux text editors unfortunately. I have suggestions for Mac or PC, but unfortunately I don't work with linux very often.

 

You should be able to use a text editor on your local machine and simply use FTP to transfer the final files to the server -- you shouldn't need to work directly on the server.

Link to post
Share on other sites
Hmm. I'm not all that familiar with Linux text editors unfortunately. I have suggestions for Mac or PC, but unfortunately I don't work with linux very often.

 

You should be able to use a text editor on your local machine and simply use FTP to transfer the final files to the server -- you shouldn't need to work directly on the server.

 

In that case vi the simplest text editor seems to do what you are saying but only locally.

Might also try Quantas like in the example. do you watch the you tube video for the simple login box?

 

Microsoft monopolizes on so many things. If you are good at working at the command line linux is just as good.

 

What editor do you use in windows? don't say pc, linux is also a pc os. people blame the pc for windows faults.

If your editor is good i could use it under vmware windows 7. is it free? That is another important thing.

Link to post
Share on other sites
Hmm. I'm not all that familiar with Linux text editors unfortunately. I have suggestions for Mac or PC' date=' but unfortunately I don't work with linux very often.

 

You should be able to use a text editor on your local machine and simply use FTP to transfer the final files to the server -- you shouldn't need to work directly on the server.[/quote']

 

In that case vi the simplest text editor seems to do what you are saying but only locally.

Might also try Quantas like in the example. do you watch the you tube video for the simple login box?

 

Microsoft monopolizes on so many things. If you are good at working at the command line linux is just as good.

 

What editor do you use in windows? don't say pc, linux is also a pc os. people blame the pc for windows faults.

If your editor is good i could use it under vmware windows 7. is it free? That is another important thing.

 

Great the box is appearing now take a look http://www.gotabeef2.com/register.php

 

here is updated register.php below

 

?php

 

include ('mysql.php');

 

echo '

nclude ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

. . $sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

 

 

now how do i get rid of the annoying echo unwanted text around the box?

Edited by billperrotta
Link to post
Share on other sites
This makes me think I don't need Kindergarten Web design ... I need Pre-School Web Design .... you Beginner's are wayyyyy over my head.

 

Well call it what you want but at least I'm trying.

 

I noticed I left out the > bracket. weird thing is I get this error if I put it back.

 

Parse error: syntax error, unexpected '.' in /homepages/21/d176117763/htdocs/register.php on line 14

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

Link to post
Share on other sites

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

 

what's up with all the dots in your source code?

 

Anyway check over your code, you for instance have forgotten to close an echo statement:

 

>
echo 'you are now registered!';

// you have:
echo 'you are now registered!'


// Also you can parse that big chunk of html without using php

} else {
?>
</pre>
<form action="register%20php" method="post">
       Username: 

       Password: 


</form>
<br><br>}<br>?&gt

Link to post
Share on other sites
This makes me think I don't need Kindergarten Web design ... I need Pre-School Web Design .... you Beginner's are wayyyyy over my head.

 

Well call it what you want but at least I'm trying.

 

I noticed I left out the > bracket. weird thing is I get this error if I put it back.

 

Parse error: syntax error' date=' unexpected '.' in /homepages/21/d176117763/htdocs/register.php on line 14

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit''])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

 

now i have see below

 

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

 

Values (0,$username,$password,time()");

 

 

echo 'you are now registered!'

}else{

echo 'you must enter a username and a password!';

}

}else{

echo '

Username:

 

Password:

 

';

 

?>

 

and getting "Parse error: syntax error, unexpected '}', expecting ',' or ';' in /homepages/21/d176117763/htdocs/register.php on line 16" it works if i remove the <? at beginning but displays the code.

 

What i am i doing wrong? i am trying to follow you tube video i posted in beginning of post.

Link to post
Share on other sites
This makes me think I don't need Kindergarten Web design ... I need Pre-School Web Design .... you Beginner's are wayyyyy over my head.

 

Well call it what you want but at least I'm trying.

 

I noticed I left out the > bracket. weird thing is I get this error if I put it back.

 

Parse error: syntax error' date=' unexpected '.' in /homepages/21/d176117763/htdocs/register.php on line 14

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit''])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

 

now i have see below

 

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

 

Values (0,$username,$password,time()");

 

 

echo 'you are now registered!'

}else{

echo 'you must enter a username and a password!';

}

}else{

echo '

Username:

 

Password:

 

';

 

?>

 

and getting "Parse error: syntax error, unexpected '}', expecting ',' or ';' in /homepages/21/d176117763/htdocs/register.php on line 16" it works if i remove the at beginning but displays the code.

 

What i am i doing wrong? i am trying to follow you tube video i posted in beginning of post.

 

as I said: echo 'you are now registered!' is missing a ; at the end.

Link to post
Share on other sites

 

Well call it what you want but at least I'm trying.

 

I noticed I left out the > bracket. weird thing is I get this error if I put it back.

 

Parse error: syntax error' date=' unexpected '.' in /homepages/21/d176117763/htdocs/register.php on line 14

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit''])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

. . . .

. . . . Values (0,$username,$password,time()");

 

. .

. . echo 'you are now registered!'

. } else {

. . echo 'you must enter a username and a password!';..

}

} else {

echo '

Username:

 

Password:

 

';

 

?>

 

now i have see below

 

?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

 

Values (0,$username,$password,time()");

 

 

echo 'you are now registered!'

}else{

echo 'you must enter a username and a password!';

}

}else{

echo '

Username:

 

Password:

 

';

 

?>

 

and getting "Parse error: syntax error, unexpected '}', expecting ',' or ';' in /homepages/21/d176117763/htdocs/register.php on line 16" it works if i remove the <? at beginning but displays the code.

 

What i am i doing wrong? i am trying to follow you tube video i posted in beginning of post.

 

as I said: echo 'you are now registered!' is missing a ; at the end.

 

not sure how this is possible there is no line 31. "Parse error: syntax error, unexpected $end in /homepages/21/d176117763/htdocs/register.php on line 31"

 

see revised below

 

<?php

 

include ('mysql.php');

 

if (isset ($_POST['submit'])) {

$username = mysql_escape_string($_POST['username']);

$password = mysql_escape_string(sha1($_POST['password']));

 

if (!empty ($username) && !empty ($password)) {

$sql = mysql_query("INSERT INTO users (user_id, username, user_regdate)

 

Values (0,$username,$password,time()");

 

 

echo 'you are now registered!';

}else{

echo 'you must enter a username and a password!';

}

}else{

echo '

Username:

 

Password:

 

';

 

?>

 

same difference if i remove <?php change to ?php it works but displays the code otherwise it complains about line line 31

or 30 1

Edited by billperrotta
Link to post
Share on other sites
}else{

echo '

Username:

 

Password:

 

';

 

well you forgot to close the else statement with a } thus the php parser is looking for that but hits the end of the file and generates the error message you are getting.

 

Which bracket? sorry to sound stupid this is the first php script I've written in my life. this bracket "[" like

this

[ }else{

echo 'you must enter a username and a password!';

}

}else{] All I am going by is the example in the you tube tutorial.

Edited by billperrotta
Link to post
Share on other sites

this is the syntax of a if else statements:

 


if (condition) {
//do something
} else {
// do something else

}

 

and this is your last else statement on the page:

 

>
}else{
       echo '</pre>
<form action="register.php" method="post">
       Username: 

       Password: 


</form>';<br

 

so if you check it you will see that you do not have a closing curly bracket in that else statement. Thus the error is generated as the php parser hits the end of the file still looking for it.

 

so adding that would resolve that particular problem.

>
}else{
       echo '</pre>
<form action="register.php" method="post">
       Username: 

       Password: 


</form>';<br>

Link to post
Share on other sites

To say what Krillz said in a slightly different way, any time you open a curly bracket "{", you need to close it "}".

 

So, if you have an if/else statement, you need to make sure it has the appropriate number of opening and closing brackets otherwise you'll get errors:

 

if (condition)
{ //opening
  code here...
} //closing
else
{ //opening
  code here...
} //closing 

Link to post
Share on other sites
To say what Krillz said in a slightly different way, any time you open a curly bracket "{", you need to close it "}".

 

So, if you have an if/else statement, you need to make sure it has the appropriate number of opening and closing brackets otherwise you'll get errors:

 

if (condition)
{ //opening
  code here...
} //closing
else
{ //opening
  code here...
} //closing 

 

Thanks so much. it works perfectly now. kinda similar to html.

planning on going through more tutorial examples. I should save my finished scripts for future reference.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...