简体   繁体   中英

PHP bug or logic error?

So here is my problem. I have a 2 tables. One for the Product details and One for the Product quantity.

In the product details there is a field Status it should be available or Not Available. Then in the Product quantity table there is a qtyleft meaning the quantity available for the product. Now the problem is i put 0 on quantity on 4 products meaning no quantity left and it should echo "Item is out of stock". It works but on 1 item only. I can't figure this out because I analyze everything and i think there is no problem. Is this a bug or what?

Here is my code:

<?php
if (isset($_GET['id']))
    {
        include('config.php');

        $id=$_GET['id'];
        $result = mysql_query("SELECT * FROM athan_products WHERE product_id = $id");
        while($row3 = mysql_fetch_array($result))
            {
                $resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE '%".$id."%'");
                //$resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE =$id");
                while($rows = mysql_fetch_array($resultq))
                    { 
                        $qwerty=$rows['qtyleft'];
                    }       
                if ($qwerty !=0){           
                    echo '<tr>';
                    //echo '<td>'.$row3['product_size_name'].'</td>';
                    echo '<td>'.$row3['price'].'</td>';
                    echo '<td>'.$row3['description'].'</td>';
                    echo '<td>'.'<input name="but" type="image" value="'.$row3['id'].'" src="images/button.png"  onclick="return myFunction()" />'.'</td>';
                    echo '</tr>';
                }
                else
                    {
                        echo '<tr>';
                        //echo '<td>'.$row3['product_size_name'].'</td>';
                        echo '<td align="center">'.'<h2>'.'Item is out of stock!'.'</td>';
                        echo '</tr>';
                        //echo '<td>'.'<h1>'.'"not available"'.'</h1>'.'</td>';
                    }
            }
    }
?>

I review your code, I think there is not any such error but you need to change you query.

$resultq = mysql_query("SELECT * FROM inventory WHERE product_id LIKE '%".$id."%'");

Into this which is given below.

$resultq = mysql_query("SELECT * FROM inventory WHERE product_id='".$id."'");

Hope you will solve your issue.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM