Page 1 of 1

echo($sql);

Posted: Sun Oct 09, 2011 11:22 pm
by Lphp
I see some php page, on some page I can use echo($sql) to see what is wrong in my php, but sometimes the echo($sql) did not get display , why? and how to temp to let the echo work??

Re: echo($sql);

Posted: Mon Oct 10, 2011 12:59 am
by social_experiment
It depends what value is inside $sql. Another option is to use die() along with the mysql_error() function. On failure, the sql error (if any) that caused the problem will be displayed. Error reporting can take on many forms but whatever the chosen method, it is a must when developing an application / script.

Code: Select all

<?php
 // look for a field that doesn't exist in the table
 $qry = "SELECT unknownFld FROM table";
 $sql = mysql_query($qry) or die(mysql_error());
 // returns 'Unknown column 'unknownFld' in 'field list'
?>

Re: echo($sql);

Posted: Mon Oct 10, 2011 3:51 am
by Lphp
thank you for the reply, ther is one of the possible reason. but I still don't understand ,if not error , I still be able to print out the who sql syntax out is that right , I still don't get why something I don't get the print out , when I use echo, is header("Location: somefile) or require cause the problem??

Re: echo($sql);

Posted: Mon Oct 10, 2011 6:43 am
by Celauran
Can you show us an example of where it isn't working?