Page 1 of 1
DIE
Posted: Wed Jun 15, 2005 2:47 pm
by Parody
I have an if statement that, if correct, should end a mysql session and die.
I have this:
Code: Select all
if (mysql_result($result,0,'tot') != 0) {
mysql_close();
die('Sorry, the username $username has already been taken');
)
I get an error on the last line, this:
What is wrong

Posted: Wed Jun 15, 2005 2:58 pm
by Chris Corbyn
Whoops....
Look again! What shape is that bracket?

Posted: Wed Jun 15, 2005 3:18 pm
by Parody
Its a ) does it need to be }?
Posted: Wed Jun 15, 2005 3:24 pm
by John Cartwright
Why don't you try it out for yourself

Posted: Wed Jun 15, 2005 3:28 pm
by Parody
I still get an error
I changed the code to this:
Code: Select all
if (mysql_result($result,0,'tot') != 0) {
mysql_close();
die{'Sorry, the username $username has already been taken'};
)
But the error is now on this line:
Code: Select all
die{'Sorry, the username $username has already been taken'};
Posted: Wed Jun 15, 2005 3:31 pm
by timvw
Go to
http://www.php.net/docs.php
Choose your language... And read 3. Language Reference... Will save you and use a lot of time

(An editor with syntax higlighting can do miracles too...)
Posted: Wed Jun 15, 2005 3:35 pm
by John Cartwright
you were closer your first time..
Code: Select all
if (mysql_result($result,0,'tot') != 0)
{
mysql_close();
die('Sorry, the username $username has already been taken');
}
a cleaner version:
Code: Select all
if (!mysql_result($result))
{
mysql_close();
die('Sorry, the username $username has already been taken');
}
Posted: Wed Jun 15, 2005 3:47 pm
by Parody
YES! Ok, from now on I will have to check all my code in good old, crappy MS Word, its the only way I can see the difference between {} and (). I am using Dreamweaver, but its almost impossible to see the difference
Thanks though
Posted: Wed Jun 15, 2005 3:49 pm
by Revan
Parody wrote:YES! Ok, from now on I will have to check all my code in good old, crappy MS Word, its the only way I can see the difference between {} and (). I am using Dreamweaver, but its almost impossible to see the difference
Thanks though
Try PHP Designer 2005.
Posted: Wed Jun 15, 2005 3:51 pm
by Parody
This is really strange also, this is one line that I have:
Code: Select all
die('Email Adress invalid, you entered: $email');
And that prints the value of $email, but this line:
Code: Select all
die('Sorry, the username "$username" has already been taken');
prints : Sorry, the username "$username" has already been taken
Eh?
Posted: Wed Jun 15, 2005 3:53 pm
by Parody
I tried PHP Designer 2005, but I stuck with Dreamweaver because I like to use it for HTML.
Posted: Wed Jun 15, 2005 3:57 pm
by John Cartwright
You must escape single quotes when parsing variables. Single quotes parses as is.
Eg.
Code: Select all
die('Sorry, the username "'.$username.'" has already been taken');
Posted: Wed Jun 15, 2005 4:04 pm
by Parody
Code: Select all
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Admin','1', '100', '2000', '001', '01', 000, '01', '01', '01',
DAMN IT!!!!!!!!
Code: Select all
mysql_query("e;INSERT INTO stats('$username','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')"e;);
That is the query
These are what the variables are set as:
Code: Select all
$username = $_POST['uname'];
$chrctr = $_POST['chrctr'];
What is wrong with the query?
Posted: Wed Jun 15, 2005 5:11 pm
by shiznatix
Code: Select all
$query = '
INSERT INTO
table_name
(row_names_go_here, other_row_names_and_whatnot)
VALUES
("'.$value_here.'", "'.$another_value.'")
';
$do_query = mysql_query($query) or die(mysql_error().__LINE__);