Help - Search - Members - Calendar
Full Version: What Kind Of Error Messages Get Returned To Browser
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Fguy
OK I am relatively new to php/mySQL, and I was trying out an INSERT from a php script. OK i have the following code block

CODE
{
    mysql_query( "INSERT INTO users VALUES ("
                +"'" +$id +"',"
                +"'" +$pwd +"',"
                +"'" +$email +"')" );

    header( "Location: menu.htm" );
}


It completes because i get redirected to menu.htm. but the INSERT doesn't work. Nothing gets added. My question is I know that some errors in php scripts get returned to the browser, but would an error in the SQL INSERT get returned? I guess not in this case. What conclusion can I draw from the fact that the header() statement executes properly?

thanks.
Bogey
I recommend you read a PHP tutorial. I'm currently in the process of writing a tutorial... I'm done to part 4 so you can start.

http://www.ozzu.com/php-tutorials/tutorial...art-t86307.html (Learning PHP (Part 1))



About that problem though, let me sum it up quickly for the above piece of code.

PHP is different than JavaScript. PHP doesn't use plus signs (+) to tie in variables to strings... PHP uses dots ( . ).

So your code would change to...
CODE
{
    mysql_query( "INSERT INTO users VALUES ("
                ."'" .$id ."',"
                ."'" .$pwd ."',"
                ."'" .$email ."')" );

    header( "Location: menu.htm" );
}


Now, another thing... the thing about PHP is, that you can have variables within double quotes... so that would change your code to...
CODE
{
    mysql_query("INSERT INTO users VALUES (
            '$id',
            '$pwd',
            '$email')");

    header( "Location: menu.htm" );
}


Hope that helped (I know you gave you the answer code but... I hope it helps in the future.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.