DIE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

DIE

Post 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:

Code: Select all

)
What is wrong :( :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Whoops....

Look again! What shape is that bracket? ;)
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Its a ) does it need to be }?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why don't you try it out for yourself ;)
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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'};
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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');
}
Last edited by John Cartwright on Wed Jun 15, 2005 3:36 pm, edited 1 time in total.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post 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.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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?
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I tried PHP Designer 2005, but I stuck with Dreamweaver because I like to use it for HTML.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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');
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post 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(&quote;INSERT INTO stats('$username','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')&quote;);
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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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__);
Post Reply