echo($sql);

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
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

echo($sql);

Post 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??
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: echo($sql);

Post 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'
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

Re: echo($sql);

Post 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??
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: echo($sql);

Post by Celauran »

Can you show us an example of where it isn't working?
Post Reply