Akenatehm Posted November 29, 2008 Share Posted November 29, 2008 Hey, I get the following error: Parse error: syntax error, unexpected $end in /home/kaurlcom/public_html/relayadmin/add_user/add_user_test.php on line 54 With the following script: <?PHP include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."',".mysql_real_escape_string; mysql_query($insert) or die("Could not insert comment" . mysql_error()); echo "User Added. <a href=\"home.html\">Click here</a> To Go Home."; } } ?> Help would be greatly appreciated. =) Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/ Share on other sites More sharing options...
GingerRobot Posted November 29, 2008 Share Posted November 29, 2008 The opening brace of the else statement in this section of code: if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { Is not closed. Though this is the cause of the error, you appear to have further problems. You are checking to see if the username exists prior to checking whether or not the form was submitted and prior to defining $username. I think you may need to rethink your logic. Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701409 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Could you give me some direction? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701410 Share on other sites More sharing options...
vicodin Posted November 29, 2008 Share Posted November 29, 2008 This should do it. <?PHP include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."',".mysql_real_escape_string; mysql_query($insert) or die("Could not insert comment" . mysql_error()); echo "User Added. <a href=\"home.html\">Click here</a> To Go Home."; } } } ?> Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701413 Share on other sites More sharing options...
GingerRobot Posted November 29, 2008 Share Posted November 29, 2008 It is closed. No, it's not. The final closing brace of the script closes this if statement: if(isset($_POST['submit'])) { Could you give me some direction? You basically need to restructure your code. You need to check to see if the username is in use after checking that the form has been submitted (the isset() if statement) and checking that the user provided a username and password. You should only insert if all those criteria are met (that is, the form has been submitted; it was submitted with a username and password provided; and the username doesn't exist. Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701415 Share on other sites More sharing options...
vicodin Posted November 29, 2008 Share Posted November 29, 2008 Ya i saw that after i posted... fixed it though... No that one is closed its the one after the else... include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { <----- ***This one is not closed*** My code above should fix the issue Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701418 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 I got the following error: Parse error: syntax error, unexpected ',' in /home/kaurlcom/public_html/relayadmin/add_user/add_user.php on line 35 Here is the code with the else statement closed (i think)" <?PHP include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."',".mysql_real_escape_string; mysql_query($insert) or die("Could not insert comment" . mysql_error()); echo "User Added. <a href=\"home.html\">Click here</a> To Go Home."; } } } ?> Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701422 Share on other sites More sharing options...
dezkit Posted November 29, 2008 Share Posted November 29, 2008 Can you point out line 35 for us? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701448 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 else if(strlen($password)<1) { print "You did not enter a password."; LINE 35 HERE: } else [/code Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701455 Share on other sites More sharing options...
dezkit Posted November 29, 2008 Share Posted November 29, 2008 Is that add_user.php? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701456 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 It's add_user_test.php Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701459 Share on other sites More sharing options...
dezkit Posted November 29, 2008 Share Posted November 29, 2008 What is line 35 of add_user.php? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701468 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 29 else if(strlen($password)<1) 30 31 { 32 33 print "You did not enter a password."; 34 35 } 36 37 else Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701470 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701489 Share on other sites More sharing options...
kenrbnsn Posted November 29, 2008 Share Posted November 29, 2008 The error is most likely caused by these lines: <?php $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."',".mysql_real_escape_string; ?> If you don't break up lines unnaturally, you would have seen that you are missing an argument on the last mysql_real_escape_string() -- it probably shouldn't even be there. Try: <?php $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string($username) . "','" . mysql_real_escape_string($password) . "','" . mysql_real_escape_string($email); ?> Ken Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701496 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 I fixed that and now I get: Could not insert commentYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''mysql_real_escape_string' at line 2 and Line 2 is blank... Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701498 Share on other sites More sharing options...
kenrbnsn Posted November 29, 2008 Share Posted November 29, 2008 Please post your current source as it exists now. Ken Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701502 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 <?PHP include "connect.php"; // Checks the database for a user with a particular user name $check = mysql_query("select ID from users where username='$username' limit 1;"); // get a row count of the number of rows found if(mysql_num_rows($check) == 1) { echo "Username Already In Use."; } else { if(isset($_POST['submit'])) { $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; if(strlen($username)<1) { print "You did not enter a username."; } else if(strlen($password)<1) { print "You did not enter a password."; } else { $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."','".mysql_real_escape_string; mysql_query($insert) or die("Could not insert comment" . mysql_error()); echo "User Added. <a href=\"home.html\">Click here</a> To Go Home."; } } } ?> Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701505 Share on other sites More sharing options...
kenrbnsn Posted November 29, 2008 Share Posted November 29, 2008 You did not change the statement I pointed out to get rid of the last mysql_real_escape_string. This: <?php $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."',".mysql_real_escape_string; ?> Needs to be <?php $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string($username) . "','" . mysql_real_escape_string($password) . "','" . mysql_real_escape_string($email); ?> Ken Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701509 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 I did change it before. Don't know why it was still showing that it hadn't. Here it is: $insert = "INSERT INTO `users` (username,password,email) VALUES ('".mysql_real_escape_string ($username)."','".mysql_real_escape_string ($password)."','".mysql_real_escape_string ($email)."','".mysql_real_escape_string; and it shows that error. Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701512 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701529 Share on other sites More sharing options...
GingerRobot Posted November 29, 2008 Share Posted November 29, 2008 Err, no. You still haven't changed it. Try actually looking at what's been posted and what you're posting. Link to comment https://forums.phpfreaks.com/topic/134706-unexpected-end-error/#findComment-701644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.