Namtip Posted November 6, 2010 Share Posted November 6, 2010 Ultimate goal is for the query to find the row in the database to avoid the validation and carry on with the rest of the script. What actually happens is the script runs without any parse errors but it doesn't find the row within mysql. $query = sprintf('SELECT name_id, title, description, price, width, height, depth, quantity FROM art WHERE product_code = "$u"', mysql_real_escape_string($product_code, $db)); $result = mysql_query($query, $db)or die(mysql_error($db)); if (mysql_num_rows($result) != 1) { header('Location: home.php'); mysql_free_result($result); mysql_close($db); exit(); } I've echoed the where variable and the mysql_num_rows($result). the where variable is as expected but the result variable comes out as 0. I've checked my phpadmin and there is a entry in there. This worked fine before I sprinted the table. Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/217947-table-doesnt-find-the-row/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 6, 2010 Share Posted November 6, 2010 sprintf uses % characters to indicate replaceable parameters. You attempted to use a php variable $u (your overall string starts and ends with single-quotes, so a php variable anywhere in it would not get replaced with it's value.) Quote Link to comment https://forums.phpfreaks.com/topic/217947-table-doesnt-find-the-row/#findComment-1131124 Share on other sites More sharing options...
Namtip Posted November 6, 2010 Author Share Posted November 6, 2010 Thank you PFMaBiSmAd. Have you got a tip box? I'd love to put some money in it. Quote Link to comment https://forums.phpfreaks.com/topic/217947-table-doesnt-find-the-row/#findComment-1131149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.