WSparrow Posted January 10, 2011 Share Posted January 10, 2011 Hi guys, I'm trying to make a basic registration page on a LAMP server. The page loads fine but after filling in the fields and hitting 'submit' it returns a blank page. The page source is also blank. I know it's not the server setup because other php pages load fine. Can anybody see a problem with my code? (It's in two files .php and .html) It's probably something stupidly simple but I've been staring at this for about 5 hours now and I'm starting to go cross-eyed. register.php: <?php include 'mysql-connect.php'; $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"); echo ' <p>Congratulations! You have successfully registered! </p> <p>Click <a href="login.php">here</a> to login.</p>'; ?> register.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Register</title> </head> <body background="Paper.JPG"> <h1>Register</h1> <form action=register.php method=post> <table><tr> <td width="81">Username:</td> <td width="247"><input name="username" size="30" value="" type="text" /></td> </tr><tr> <td>Password:</td> <td><input name="password" size="30" type="password" /></td> </tr> <tr> <td>First Name:</td> <td><input name="firstname" size="30" type="text" /></td> </tr> <tr> <td>Last Name:</td> <td><input name="lastname" size="30" type="text" /></td> </tr> <tr> <td>Email:</td> <td><input name="email" size="30" maxlength="100" /></td> </tr> </table> <p><input type="submit" class="button" value="Register" /></p> </form> </body> </html> THANKS Link to comment https://forums.phpfreaks.com/topic/223997-typo/ Share on other sites More sharing options...
Rifts Posted January 10, 2011 Share Posted January 10, 2011 first try just echoing out your vars then slowly build and test build and test. I'm sure you will get it working Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157532 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 if you're not seeing an error, you probably have error_reporting turned off. try adding these lines at the top of the file and see if you get an error error_reporting(E_ALL); ini_set("display_errors", -1); the error is Parse error: syntax error, unexpected $end Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157533 Share on other sites More sharing options...
Pikachu2000 Posted January 10, 2011 Share Posted January 10, 2011 You should be developing on a system with error reporting set to the highest level, and display_errors on. You've left off a closing curly brace for your else statement. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157538 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 Thanks, I've upped the error reporting. Tried adding the curly bracket, and it's reporting that as the error. I'll keep at it and report back. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157551 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 Okay, after removing the curly brace and trying again with the original file, I get: PHP Parse error: syntax error, unexpected T_ECHO in /var/www....... Any thoughts? Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157556 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 yes, you left off the most important part of the error: where it is PHP Parse error: syntax error, unexpected T_ECHO in /var/www....... on line ????? Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157560 Share on other sites More sharing options...
Pikachu2000 Posted January 10, 2011 Share Posted January 10, 2011 Post your revised code, within the forum's . . . BBCode tags, please. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157561 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 FYI: watch for your document encoding in that code. I had to change it to get it to parse. Are you using Wordpad or something? Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157562 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"); echo '<p>Congratulations! You have successfully registered! </p><p>Click <a href="login.php">here</a> to login.</p>'; } // missing bracket. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157565 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 I'm using gedit. Can't try these things as fast as you guys are posting them lol okay the full error it gave me is: PHP Parse error: syntax error, unexpected T_ECHO in /var/www/html/www.***.com/register.php on line 21, referer: http://www.***.com/register.html error_reporting(E_ALL); <?php include 'mysql-connect.php'; $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')" echo ' <p>Congratulations! You have successfully registered! </p> <p>Click <a href="login.php">here</a> to login.</p>'; } ?> @bluesky I'll try that now. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157574 Share on other sites More sharing options...
Pikachu2000 Posted January 10, 2011 Share Posted January 10, 2011 The previous line isn't terminated with a semi-colon. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157580 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 I thought that was wrong. Originally there was a semi-colon there but the error log said that was wrong. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157582 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 I'm unclear about the document type comment though. Does it matter which editor I'm using? I'm using gedit with char encoding set to "current locale UTF-8" Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157584 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 Tried putting back the semi-colon and again the error log says: PHP Parse error: syntax error, unexpected ';' in ..... on line 15 Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157591 Share on other sites More sharing options...
Pikachu2000 Posted January 10, 2011 Share Posted January 10, 2011 The closing parenthesis on that line belongs outside of the closing double quote . . . Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157598 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 It is outside of the double quote. The current edit of the file (which is getting the parse error at the semi-colon) is: error_reporting(E_ALL); <?php include 'mysql-connect.php'; $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"; } echo ' <p>Congratulations! You have successfully registered! </p> <p>Click <a href="login.php">here</a> to login.</p>'; } ?> I did notice that the html was ISO and the php was UTF so I changed it so they're both using utf-8, but that didn't make any difference. Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157614 Share on other sites More sharing options...
Imaulle Posted January 10, 2011 Share Posted January 10, 2011 maybe this? <?php error_reporting(E_ALL); require_once('mysql-connect.php'); $username = $_POST['username']; $password = $_POST['password']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $result = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE username='$username'")); if($result == 1) { echo '<h1>ERROR!</h1>The username you have chosen already exists!'; } else { mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"); echo "<p>Congratulations! You have successfully registered!</p><br><p>Click <a href=\"login.php\">here</a> to login.</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157635 Share on other sites More sharing options...
BlueSkyIS Posted January 10, 2011 Share Posted January 10, 2011 The closing parenthesis on that line belongs outside of the closing double quote . . . the problem is missing closing paren in the mysql_query() call. mysql_query("INSERT INTO accounts (username, password, firstname, lastname, email) VALUES ('$username', '$password', '$firstname', '$lastname', '$email')"); Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157637 Share on other sites More sharing options...
WSparrow Posted January 10, 2011 Author Share Posted January 10, 2011 I just noticed that actually. I made the change and now there are no errors in the log. Instead when you fill out the form and hit 'submit' it just loads the form data into the address bar. I'll have to check my socket configuration I guess. THANKS EVERYONE!! Link to comment https://forums.phpfreaks.com/topic/223997-typo/#findComment-1157639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.