Newbie question
Moderator: General Moderators
Newbie question
I'm making a registration script for my website, and i have it so the form adds the info into a mysql database. I get this error when i submit the information:
Parse error: parse error, unexpected T_ELSE in d:\inetpub\wwwroot\register.php on line 23
I have no idea what that means, can anyone help me out?
The code is here:
http://24.157.207.35/register.txt
and that includes a file called common_db.inc
which is at http://24.157.207.35/common_db.inc for your viewing.
Any help appreciated, thanks!
Parse error: parse error, unexpected T_ELSE in d:\inetpub\wwwroot\register.php on line 23
I have no idea what that means, can anyone help me out?
The code is here:
http://24.157.207.35/register.txt
and that includes a file called common_db.inc
which is at http://24.157.207.35/common_db.inc for your viewing.
Any help appreciated, thanks!
ummm ... this is going to give you problems :
you either need to have
"WHERE USERID=$nickname" on every one after the first as so :
or add all the info at once .. which would be better - such as in:
Code: Select all
$result = mysql_query("INSERT INTO user (userid)
VALUES('$nickname')");
$result = mysql_query("INSERT INTO user (userpassword)
VALUES('$password')");
$result = mysql_query("INSERT INTO user (username)
VALUES('$realname')");
$result = mysql_query("INSERT INTO user (usercountry)
VALUES('$country')");
$result = mysql_query("INSERT INTO user (useremail)
VALUES('$email')");
$result = mysql_query("INSERT INTO user (userprofile)
VALUES('$profile')");
$result = mysql_query("INSERT INTO user (registerdate)
VALUES('date()')");"WHERE USERID=$nickname" on every one after the first as so :
Code: Select all
$result = mysql_query("INSERT INTO user (userid)
VALUES('$nickname')");
$result = mysql_query("INSERT INTO user (userpassword)
VALUES('$password') WHERE USERID=$nickname");
etc .....Code: Select all
$result = mysql_query("INSERT INTO user (userid, userpassword, username, usercountry, useremail, userprofile, registerdayt) VALUES('$nickname','$password','$realname','$country','$email','$profile','date()')");RE
Ok thanks for your help, i took out the first else if and changed it to an if, and i made it so that it adds everything to $result right away.
Now i get an error
Parse error: parse error, unexpected T_STRING in d:\inetpub\wwwroot\register.php on line 24
Line 24 looks like this:
Also, just another quick question, im storing everything to a variable $result which is supposed to input the information into the mysql database, however do i have to do anything other than:
Will that automatically insert it into the mysql database, or do i have to do something with the variable $result ?
Now i get an error
Parse error: parse error, unexpected T_STRING in d:\inetpub\wwwroot\register.php on line 24
Line 24 looks like this:
Code: Select all
else if(!$nickname) die("You must enter a nickname");Code: Select all
$result = mysql_query("INSERT INTO user (userid, userpassword, username, usercountry, useremail, userprofile, registerdayt) VALUES('$nickname','$password','$realname','$country','$email','$profile','date()')");Ok i fixed everything, except for one thing:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in d:\inetpub\wwwroot\register.php on line 43
The block of code that generates that error is the thing that checks to see if the username they have submitted is already in the database..
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in d:\inetpub\wwwroot\register.php on line 43
The block of code that generates that error is the thing that checks to see if the username they have submitted is already in the database..
Code: Select all
Line 42:$result = mysql_query("SELECT * FROM user WHERE username = '$username'");
Line43:if(mysql_num_rows($result) != 0) die("That username is already in use. Please choose another");- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try changing this:
to
and you should hopefully get a more useful error message.
Mac
Code: Select all
$result = mysql_query("SELECT * FROM user WHERE username = '$username'");Code: Select all
$sql = "SELECT * FROM user WHERE username = '$username'";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');Mac
When i substituted that in for line 42/43 it worked fine-but it didnt check to see if the username is already in use.
I have a table called users, which has values for user_name and password. I just want to check the username that the person submits through the form against what is in the table user_name.. if they submitted 'frank' and frank was already in use, i want it to return an error message saying so.
like i said, i was using this:
But i get an error: T_STRING or something.
I have a table called users, which has values for user_name and password. I just want to check the username that the person submits through the form against what is in the table user_name.. if they submitted 'frank' and frank was already in use, i want it to return an error message saying so.
like i said, i was using this:
Code: Select all
$result = mysql_query("SELECT * FROM users WHERE user_name = '$username');
if(mysql_num_rows($result) != 0) die("That username is already in use");- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
The reason for the T_STRING error is because you're missing a closing double quotes on your SQL statement. You should have only substitued line 42 with the two lines of code I gave you, if you haven't already, try:
Getting into the habit of separating the SQL statement out of the mysql_query() call is a good habit to get into as it can save you a lot of headaches when your queries get more complicated and you pass more variables into them.
Mac
Code: Select all
$sql = "SELECT * FROM user WHERE username = '$username'";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
if (mysql_num_rows($result) != 0) {
die ('That username is already in use.');
} else {
echo 'The username you have chosen is '.$username.', and it is unique.';
}Mac