Floore Posted March 30, 2010 Share Posted March 30, 2010 I have been learning PHP over the last week or so, currently trying to write a login script and I am now constantly getting a blank page showing no errors. I have no idea what is wrong but my form just will not process. I've cut bits of code out and written it different ways, but there seems to be no answer! Can anyone help? Here is my code: (I have hashed out the login info but I am 100% sure it's correct) <?php //Show me my mistakes! ini_set('display_errors', 1); error_reporting (E_ALL); //Connect to the database $host = "#"; $port = 3306; //The default port for mySQL is 3306 $username = "#"; $password = "#"; $database = "#"; mysql_connect($host, $username, $password) or Die("Couldn't Connect: " . mysql_error()); mysql_select_db($database) or Die("Couldn't connect to database: " . mysql_error()); //Confirm submission of the form (and not direct access) $user = $_POST['username']; $pass = $_POST['password']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $email2 = $_POST['email2']; $sex = $_POST['sex']; $firstline = $_POST['firstline']; $town = $_POST['town']; $postcode = $_POST['postcode']; //Check 1/2 - Find out if the user still exists $find_user_query = mysql_query("SELECT * FROM accounts WHERE username = $user") or Die("Couldn't connect: " . mysql_error(); $find_user = mysql_num_rows($find_user_query); //If so, notify the user and ask for an alternative if ($find_user > 0) { echo "User $user already exists, please choose another username<br /><br />"; echo "<p><div style=\"width: 550px; padding: 20px; background-color: #FFAA00\"> <form class=\"createuser\" name=\"create\" action=\"createuser.php\" method=\"POST\"> <b>Personal Information:</b><br /><br /> <label for=\"username\">Username: <font color=\"red\">*</font></label> <input type=\"text\" name=\"username\" value=\"\" /><br /> <label for=\"password\">Password: <font color=\"red\">*</font></label> <input type=\"password\" name=\"password\" value=\"\" /><br /> <label for=\"firstname\">First Name: <font color=\"red\">*</font></label> <input type=\"text\" name=\"firstname\" value=\"$firstname\" /><br /> <label for=\"lastname\">Last Name: <font color=\"red\">*</font></label> <input type=\"text\" name=\"lastname\" value=\"$lastname\" /><br /> <label for=\"email\">E-mail: <font color=\"red\">*</font></label> <input type=\"text\" name=\"email\" value=\"$email\" /><br /> <label for=\"email2\">Confirm E-mail: <font color=\"red\">*</font></label> <input type=\"text\" name=\"email2\" value=\"$email2\" /><br /> <label for=\"sex\">Sex:</label> <input type=\"radio\" name=\"sex\" value=\"M\" /> Male <input type=\"radio\" name=\"sex\" value=\"F\" /> Female<br /> <label for=\"firstline\">First Line of Address: <font color=\"red\">*</font></label> <input type=\"text\" name=\"firstline\" value=\"$firstline\" /><br /> <label for=\"town\">Town: <font color=\"red\">*</font></label> <input type=\"text\" name=\"town\" value=\"$town\" /><br /> <label fpr=\"postcode\">Post Code: <font color=\"red\">*</font></label> <input type=\"text\" name=\"postcode\" value=\"$postcode\" /><br /> <label for=\"submit\"> </label><input type=\"submit\" value=\"Sign Up\" /> </form> </div>"; //Check 2/2 - If username is free, check for any blank fields } elseif (empty($user) || empty($pass) || empty($firstname) || empty($lastname) || empty($email) || empty($sex) || empty($firstline) || empty($town) || empty($postcode)) { echo "Please fill out ALL Required fields<br /><br /><br />"; echo "<div style=\"width: 550px; padding: 20px; background-color: #FFAA00\"> <form class=\"createuser\" name=\"create\" action=\"createuser.php\" method=\"POST\"> <b>Personal Information:</b><br /><br /> <label for=\"username\">Username: <font color=\"red\">*</font></label> <input type=\"text\" name=\"username\" value=\"$user\" /><br /> <label for=\"password\">Password: <font color=\"red\">*</font></label> <input type=\"password\" name=\"password\" value=\"\" /><br /> <label for=\"firstname\">First Name: <font color=\"red\">*</font></label> <input type=\"text\" name=\"firstname\" value=\"$firstname\" /><br /> <label for=\"lastname\">Last Name: <font color=\"red\">*</font></label> <input type=\"text\" name=\"lastname\" value=\"$lastname\" /><br /> <label for=\"email\">E-mail: <font color=\"red\">*</font></label> <input type=\"text\" name=\"email\" value=\"$email\" /><br /> <label for=\"email2\">Confirm E-mail: <font color=\"red\">*</font></label> <input type=\"text\" name=\"email2\" value=\"$email2\" /><br /> <label for=\"sex\">Sex:</label> <input type=\"radio\" name=\"sex\" value=\"M\" /> Male <input type=\"radio\" name=\"sex\" value=\"F\" /> Female<br /> <label for=\"firstline\">First Line of Address: <font color=\"red\">*</font></label> <input type=\"text\" name=\"firstline\" value=\"$firstline\" /><br /> <label for=\"town\">Town: <font color=\"red\">*</font></label> <input type=\"text\" name=\"town\" value=\"$town\" /><br /> <label fpr=\"postcode\">Post Code: <font color=\"red\">*</font></label> <input type=\"text\" name=\"postcode\" value=\"$postcode\" /><br /> <label for=\"submit\"> </label><input type=\"submit\" value=\"Sign Up\" /> </form> </div>"; //If everything is OK, allow the user to be created and present them with the login page } else { $query = "INSERT INTO accounts (username, password, firstname, lastname, email, sex, firstline, town, postcode) VALUES ('$user', '$pass', '$firstname', '$lastname', '$email', '$sex', '$firstline', '$town', '$postcode'"; if (@mysql_query($query)) { echo 'User created, please login below:'; echo '<form class="login" name="login" action="signin.php" method="POST">'; echo '<label for="username">Username: </label><input type="text" name="username" maxlength="12"><br /> <label for="password">Password: </label><input type="password" name="password" maxlength="12"> <input type="submit" name="submit" value="submit"> </form>'; } else { echo "Could not complete request for the following reason: " . mysql_error(); echo "<br /><br />The query being run was: " . $query; } mysql_close() } //All Done!! New User!! ?> Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 30, 2010 Share Posted March 30, 2010 Blank pages are usually due to fatal parse errors. In your case - Parse error: syntax error, unexpected ';' in your_file.php on line 35 You must set the error_reporting/display_errors settings before your script is requested in order to show fatal parse errors. Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034185 Share on other sites More sharing options...
Floore Posted March 30, 2010 Author Share Posted March 30, 2010 Before my script is requested? What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034191 Share on other sites More sharing options...
ignace Posted March 30, 2010 Share Posted March 30, 2010 php.ini Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034200 Share on other sites More sharing options...
Floore Posted March 30, 2010 Author Share Posted March 30, 2010 I'm not using localhost, it's an online server and I've not had this problem before. Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034203 Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 what error is it ouputting? u susing an index.php file with this displayed in it? Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034206 Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 Found it.... $find_user_query = mysql_query("SELECT * FROM accounts WHERE username = $user") or Die("Couldn't connect: " . mysql_error(); should be $find_user_query = mysql_query("SELECT * FROM accounts WHERE username = '$user') or Die("Couldn't connect: " . mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034208 Share on other sites More sharing options...
PFMaBiSmAd Posted March 30, 2010 Share Posted March 30, 2010 You should be learning php (or learning anything new in php), developing php code, and debugging php code on a local development system. Constantly uploading code to a live server just to see what it does or if it works wastes a huge amount of time. If necessary, you can set those two values in a local php.ini (when php is running as a CGI application) or in a .htaccess file (when php is running as an Apache Module.) Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034210 Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 ok lots here... echo "User $user already exists, please choose another username<br /><br />"; to echo 'User'. $user.' already exists, please choose another username<br /><br />'; any verible in text needs to be sep from the echoed text... echo 'the textt'.$array.'more text' Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034211 Share on other sites More sharing options...
runnerjp Posted March 30, 2010 Share Posted March 30, 2010 Also just doing $_POST['username']; is a huge securtity risk and asks for sql injection. http://www.addedbytes.com/writing-secure-php/ take alook at the above website...helped me out loads Quote Link to comment https://forums.phpfreaks.com/topic/196996-blank-page-pulling-my-hair-out/#findComment-1034213 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.