0

Hello I'm trying to update a column in my mysql table and I can't get it working.

When I'm trying to click confirm, it doesn't change anything.

orders.php

<?php while ($row = mysqli_fetch_array($results)) { ?>
    <tr>

        <td><?php echo $row['fullname']; ?></td>
        <td><?php echo $row['address']; ?></td>
        <td><?php echo $row['mobile']; ?></td>
        <td><?php echo $row['order_item']; ?></td>
        <td><?php echo $row['quantity']; ?></td>
        <td><?php echo $row['total_amount']; ?></td>
        <td><?php echo $row['payment']; ?></td>
        <td><?php echo $row['status']; ?></td>
        <td>
            <a href="vieworders.php?pending=<?php echo $row['id']; ?>" class="edit_btn"  onclick="return confirm('Update status?');">Pending</a>
        </td>
        <td>
            <a href="vieworders.php?confirm=<?php echo $row['id']; ?>" class="del_btn" onclick="return confirm('Update status?');">Confirm</a>
        </td>
    </tr>
<?php } ?>

admin.php

if (isset($_POST['pending'])) {

$pending = "Pending";
$id = $_POST['id'];
mysqli_query($db, "UPDATE order_information SET status='$pending' WHERE id=$id");
array_push($success, "Update SUCCESS");
}

if (isset($_POST['confirm'])) {

$confirm = "Confirm";
$id = $_POST['id'];
mysqli_query($db, "UPDATE order_information SET status='$confirm' WHERE id=$id");
array_push($success, "Update SUCCESS");
}
  • What have you tried to debug this? Are you sure about checking for `$_POST` while issuing a `GET` request? Are there any errors thrown by the MySQL server? – Nico Haase Aug 19 '18 at 16:37
  • 1
    Possible duplicate of [When should I use GET or POST method? What's the difference between them?](https://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them) – Nico Haase Aug 19 '18 at 16:38
  • @NicoHaase where can I check the errors of my mysql? I'm using phpmyadmin – user3857974 Aug 19 '18 at 16:44
  • 1
    Well, first have a look at the difference between `GET` and `POST`. If you understood that, have a look at debugging of code - some `echo` here and there is already enough to see which parts of your code are triggered and which are not. Finally, `mysqli_error` might help out if you are completely sure that the MySQL query is executed after all – Nico Haase Aug 19 '18 at 16:45

2 Answers2

0

You are expecting a http Post on your script whilst you are making a Get request by clicking on the link.

Try this instead

if (isset($_REQUEST['pending'])) { 
$pending = "Pending"; 
$id = mysqli_real_escape_string($db,$_REQUEST['id']); 
mysqli_query($db, "UPDATE order_information SET status='$pending' WHERE id=$id");
 array_push($success, "Update SUCCESS"); 
} 

if (isset($_REQUEST['confirm'])) {
 $confirm = "Confirm"; 
 $id = mysqli_real_escape_string($db,$_REQUEST['id']); 
mysqli_query($db, "UPDATE order_information SET status='$confirm' WHERE id=$id");
 array_push($success, "Update SUCCESS");
 }

Notice I escaped you inputs... It's a good habit that can save you from peti-hackers trying out SQL injections

I hope this helps you. Don't mind my rusty typing. Still not use the the mobile app

Chuka Okoye
  • 132
  • 3
0

Your href goes to vieworders.php, which is a $_GET, how did you link up admin.php. in vieworders.php, your id will be in the $_GET.

Olusola Omosola
  • 847
  • 9
  • 9