I'm coding a registration form and I'm a newbie. I did all the basic stuff and closed my PHP, but it still says there's a parse error on the line my PHP closes.
PHP Code:
<?php //This is just starting a session. session_start();
//Either this thing connects, or it's gunna die. $con = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error()); mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
//First, we store the information gathered from the form in variables. $username=$_POST['username']; $pass=$_POST['password']; $email=$_POST['email'];
$password=md5($pass); //Here, we use the md5() function to encrypt the user's password. $confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
$queryuser=mysql>("SELECT * FROM people WHERE username='$username'"); $checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.
$queryemail=mysql>("SELECT * FROM people WHERE email='$email'"); $checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.
if($checkuser != 0) { echo "Sorry, ".$username." is already taken."; } //If the username is already taken, it will display a message. else { if($pass != $confirm_password) //Checks to see if the two passwords macth or not. { echo "Your passwords don't match."; } else { if($checkemail != 0) //if the email is already taken, it will display a message. { echo "Sorry, ".$email." is already registered.."; } else { if($username="") //Checks to see if the user actually inserted a username. { echo "Please provide a username."; } else { if($password="") //Checks to see if the user actually inserted a password. { echo "Please provide a password."; } else { if($email="") //Checks to see if the user actually inserted an email address. { echo "Please provide an email address."; } else { $insert_user = mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); }; //Inserts the data if everything checks out okay.
if($insert_user) //Did the information successfully insert into the database? { echo "You successfully registered!"; } //If yes, then congrats! else { echo "Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.
mysql_close($con); //Closes the connection made in the dbconnect.php script.
Thanks, nomanic. I was stupid not to realize that. :P
But even after fixing it, my PHP Syntax checker (VERY useful!) built into my IDE said there was another parse error on line 36. >:/
PHP Code:
else { <--Line in question. if($checkemail != 0) //if the email is already taken, it will display a message. { echo "Sorry, ".$email." is already registered.."; } } else { if($username="") //Checks to see if the user actually inserted a username. { echo "Please provide a username."; } } else { if($password="") //Checks to see if the user actually inserted a password. { echo "Please provide a password."; } } else { if($email="") //Checks to see if the user actually inserted an email address. { echo "Please provide an email address."; } } else { $insert_user = mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); };
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
i sure, code will do "insert new username" even when posted variable are empty. all check will return true, because you not compare the value. look:
PHP Code:
if($username="")
that's not mean "if $username is empty". so you need to compare values with just replace "=" with "==".
PHP Code:
if($username=="")
then, you don't close any open statement. i moded your code to look better, so we easy to trace where is a problem, and i know if any unclosed statement on your code.
PHP Code:
<?php
//This is just starting a session.
session_start();
//Either this thing connects, or it's gunna die.
$con = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
//First, we store the information gathered from the form in variables.
$username=$_POST['username'];
$pass=$_POST['password'];
$email=$_POST['email'];
$password=md5($pass); //Here, we use the md5() function to encrypt the user's password.
$confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
$queryuser=mysql>("SELECT * FROM people WHERE username='$username'");
$checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.
$queryemail=mysql>("SELECT * FROM people WHERE email='$email'");
$checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.
if($checkuser != 0){
echo "Sorry, ".$username." is already taken.";
} //If the username is already taken, it will display a message.
else {
if($pass != $confirm_password){
echo "Your passwords don't match.";
}//Checks to see if the two passwords macth or not.
else {
if($checkemail != 0){ //if the email is already taken, it will display a message.
echo "Sorry, ".$email." is already registered..";
}
else {
if($username==""){ //Checks to see if the user actually inserted a username.
echo "Please provide a username.";
}
else {
if($password==""){ //Checks to see if the user actually inserted a password.
echo "Please provide a password.";
}
else {
if($email==""){ //Checks to see if the user actually inserted an email address.
echo "Please provide an email address.";
}
else {//Inserts the data if everything checks out okay.
$insert_user = mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')");
};
if($insert_user) //Did the information successfully insert into the database?
{ echo "You successfully registered!"; } //If yes, then congrats!
else
{ echo "Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.
mysql_close($con); //Closes the connection made in the dbconnect.php script.
######### from here, you not close any statement, so just closed it #############
}
}
}
}
}
############# eof ##############
Thanks, tango, but I would prefer to stick with my current editor. All I need right now is a fix to this cursed parse error. :/
You will be seeing a lot more parse errors unless you change your STYLE of coding. I didn't suggest you change editors, my post uses Notepad++ but any editor is capable of using those coding styles.
If you always have your opening and closing braces {} on a seperate line and indented it makes your code far easier to read. Trust me, I used to code like you, it got sloppy and infuriating to fix. It's up to you if you want to listen to someone with experience or not.
Look at this:
PHP Code:
function a()
{
function b()
{
function c()
{
function d()
{
//See how much easier this is to understand?
}
}
}
}
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.