Jump to content

Blank page, pulling my hair out


Floore

Recommended Posts

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!!

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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'

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.