View Full Version : PHP script wont get contents of MYSQL DB

03-12-2007, 11:01 AM

Does anyone see anything wrong with the below? What it tries to do is get an email address stored in a field called value and then print it out but for some reason the value it returns is empty. The strange thing is that it works when i use anything other then email like if value is firstname it works great and returns the first name and so on with other values like company, last name etc...

PS The WHERE email=\"$email\" portion of the script is a controller and not the email i am trying to get.



$query = "SELECT value FROM imports WHERE email=\"$email\" AND controller=1 AND field=\"$emailfield\" ORDER BY controller";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC))


03-12-2007, 04:15 PM
Well, since the query works in other situations, then you've got to think it's either the data isn't there, or the query isn't doing what you think it should be doing for the data that is there.

To troubleshoot, I would stick a "die($query)" statement in right after you build the query text. This will simply echo to the browser the exact query you are running. Then copy/paste that query into an ad-hoc query tool such as PhpMyAdmin, and see what results you get. If the results are just as you expected, then the problem is the PHP code. If not, then the problem is with the query.