In article <007901c0b153$ae861a80$660083ca@oemcomputer>,
 [EMAIL PROTECTED] ("Mick Lloyd") wrote:

> Thanks for the reply. I tried the variable route but again failed. I think
> from your suggested line of code you may have misunderstood the problem. The
> LIKE option works fine without having to put it into a variable.
> 
> $sql = "select Primaryid from primarycodes where Code =
> '$row[Primaryexpertise]'";
> print $sql."<BR>\n";
> 
> \\Prints: select Primaryid from primarycodes where Code = 'Biology' \\which
> seems OK
> 
> $resultp = mysql_query($sql) or die ("Failed"); \\This seems to work
> $pcodeid = mysql_fetch_array($resultp) or die("No pcodeid");
> 
> \\Prints: No pcodeid \\ie failed

mysql_query() returns true as long as the query syntax appears valid; it 
does not indicate whether the query actually found rows or not.  So just 
because the code didn't die on the mysql_query() line, you cannot assume 
the query "works" as intended.  The fact that the mysql_fetch_array() line 
dies would suggest that the query above likely is failing for some reason.  
One thing you can do is check mysql_num_rows() first to determine whether 
the query found any records.  Another thing you can do is echo $sql, then 
copy/paste that query at the command line to determine whether it's the SQL 
itself that's the problem or the PHP code.  Finally, instead of displaying 
your own ambiguous error messages on die(), let MySQL & PHP report to you 
what they know about the problem.  Example:

$resultp = mysql_query($sql) or die('Query failed.  MySQL says: ' . 
mysql_error() . '. PHP says: ' . $errormsg . '.');

-- 
CC

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to