Ames Posted April 9, 2007 Share Posted April 9, 2007 Hi guys, I'm new here and have just started learning to program. At the moment I am writing a simple login and registration script. My problem is that I keep getting this message Parse error: parse error, unexpected T_ECHO in C:\Program Files\xampp\htdocs\forum_new\register.php on line 33 Here is the script: <?php include("config.php"); $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $check = "select id from $table where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo ("Sorry, there the username $username is already taken.<br>"); echo ("<a href=register.html>Try again</a>"); exit; } else { $insert = mysql_query("INSERT INTO $table (user_name, password, email) VALUES ('" . $_POST["txtusername"] . "', '" . $_POST["txtpassword"] . "', '" . $_POST["txtemail"] . "')" or die ("Could not insert data because ".mysql_error()) echo ("Your user account has been created!<br>"); // this is the line reported as error echo ("Now you can <a href=login.html>log in</a>"); } ?> The line in question is in bold. I have tried everything, removing the brackets, quotes, semi colon, adding a semi colon at the end of the above line. Nothing seems to work. I would be very greatful if you guys could provide any help. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 9, 2007 Share Posted April 9, 2007 Every statement needs to end with a semicolon. You should have one at the end of the die statement above the echo line. Quote Link to comment Share on other sites More sharing options...
Ames Posted April 9, 2007 Author Share Posted April 9, 2007 I have tried what you said but now I get this error Parse error: parse error, unexpected ';' in C:\Program Files\xampp\htdocs\forum_new\register.php on line 31 This relates to the die statement, the semi colon which I just added. Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 9, 2007 Share Posted April 9, 2007 You're also missing a parenthesis. $insert = mysql_query("INSERT INTO $table (user_name, password, email) VALUES ('" . $_POST["txtusername"] . "', '" . $_POST["txtpassword"] . "', '" . $_POST["txtemail"] . "')") or die ("Could not insert data because ".mysql_error()); Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 9, 2007 Share Posted April 9, 2007 I should also mention you never want to insert POST or GET data directly into your database. At a minimum you should wrap them in mysql_real_escape_string... mysql_query("INSERT INTO $table (user_name, password, email) VALUES ('" . mysql_real_escape_string($_POST["txtusername"]) . "', '" . mysql_real_escape_string($_POST["txtpassword"]) . "', '" . mysql_real_escape_string($_POST["txtemail"]) . "')") But you should probably do some data validation first (like no spaces in passwords, valid chars in username, etc.) So check POST and GET for security and data validation. Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 9, 2007 Share Posted April 9, 2007 $insert = mysql_query("INSERT INTO $table (user_name, password, email) VALUES ('" . $_POST["txtusername"] . "', '" . $_POST["txtpassword"] . "', '" . $_POST["txtemail"] . "')" ;(Semicolon) Quote Link to comment Share on other sites More sharing options...
Ames Posted April 9, 2007 Author Share Posted April 9, 2007 Thanks very much for all of your help. Problem solved Quote Link to comment Share on other sites More sharing options...
Ames Posted April 9, 2007 Author Share Posted April 9, 2007 Well i thought the problem was solved, but I was wrong. I have tried all of the suggestions that you guys have kindly given me but no matter what I do the same error keeps turning up. Parse error: parse error, unexpected ';' in C:\Program Files\xampp\htdocs\forum_new\register.php on line 31 Which relates to the semi colon added after the die statement. If I remove this then I get this error: Parse error: parse error, unexpected T_ECHO in C:\Program Files\xampp\htdocs\forum_new\register.php on line 33 As you can see by removing the semi colon there is no problem with the "die" line. However I know that it is needed. I have also tried everything I can think of to try and fix the T_ECHO but with no luck. If anyone can help it will be really appreciated. Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 9, 2007 Share Posted April 9, 2007 Your statement above the echo should look like $insert = mysql_query(...) or die(...); The die isn't an independent statement in this case. And at one point your mysql_query() call was missing the right parenthesis. If all of the parens are closed and the semicolon is there you still get an error? Because the only other possible syntax problem would be quoting, but those look OK. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.