Jump to content

Table doesn't find the row.


Namtip

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/217947-table-doesnt-find-the-row/
Share on other sites

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.