-2

I am trying to create a shopping cart to my business application i already write this code it doesn't gives me any error but it doesn't retrive the data that are in the database

cart.php looks like this

$last_id = mysqli_insert_id($con);
$_SESSION['last_id'] = $last_id;
$sql = "SELECT * FROM product_order WHERE ord_id = '$last_id'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);

I created a table to display the data

<tr>
                        <th width="5%">Last Id</th>
                        <th width="5%">Order id</th>
                        <th width="5%">Selected Card</th>
                        <th width="15%">Field 1</th>
                        <th width="15%">Field 2</th>
                        <th width="15%">Field 3</th>
                        <th width="15%">Field 4</th>
                        <th width="15%">Field 5</th>
                        <th width="5%">Quantity</th>
                        <th width="5%">Price</th>
                        <th width="5%">Total</th>
                        <th width="15%">Action</th>
                    </tr>
                    <tr>
                    <td><?php echo $last_id?></td>
                    <td><?php echo $row['ord_id']?></td>
                    <td><?php echo $row['card_id']; ?></td>
                    <td><?php echo $row['field1']; ?></td>
                    <td><?php echo $row['field2']; ?></td>
                    <td><?php echo $row['field3']; ?></td>
                    <td><?php echo $row['field4']; ?></td>
                    <td><?php echo $row['field5']; ?></td>
                    <td><?php echo $row['quantity']; ?></td>
                    <td><?php echo $row['price']; ?></td>
                    <td><?php echo $total ?></td>
  • 1
    you're open to SQL injection and should address imminently – treyBake Sep 28 '19 at 18:00
  • Check your errors by this: ```ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);``` – Mohammadreza Yektamaram Sep 28 '19 at 18:15
  • you are fetching an array of rows as $row -> you need a foreach loop or similar to output your table rows – GrahamTheDev Sep 28 '19 at 18:17
  • i type it after this line `$row = mysqli_fetch_assoc($result);` but doesn't gives me a error @MohammadrezaYektamaram – Craft Cover Sep 28 '19 at 18:17
  • `if(mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_array($result)){ ` i tried this but now it is just a white page nothing there @GrahamRitchie – Craft Cover Sep 28 '19 at 18:27
  • Possible duplicate of [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Sep 28 '19 at 22:29

1 Answers1

-1

try this syntax :

$sql = "SELECT * FROM product_order WHERE ord_id =" . $last_id;

and

  <?php foreach ($row as $r) : ?>
  <td><?php echo $r['ord_id']?></td>
  <td><?php echo $r['card_id']; ?></td>
  <td><?php echo $r['field1']; ?></td>
  <td><?php echo $r['field2']; ?></td>
  <td><?php echo $r['field3']; ?></td>
  <td><?php echo $r['field4']; ?></td>
  <td><?php echo $r['field5']; ?></td>
  <td><?php echo $r['quantity']; ?></td>
  <td><?php echo $r['price']; ?></td>
  <?php endforeach; ?>