Home > other >  Update function not working in php orders table
Update function not working in php orders table

Time:05-28

    <?php
include "server.php";
if (isset($_GET['id'])) {
    $id= $_GET['id'];
    $result = mysqli_query($conn,"SELECT * FROM orders WHERE id = $id");
    $row = mysqli_fetch_array($result) ;
}

?>
<?php
if (isset($_POST['update'])) {

    

    //$id=$_POST['id'];
   $id= $_GET['id'];
    
    $query = "UPDATE `orders` SET `fullname`='$_POST[fullname]', `phonenumber`='$_POST[phonenumber]', `email`='$_POST[email]', `services`='$_POST[services]' WHEN `id`=$id";
    $query_run = mysqli_query($conn,$query);
    
    if($query_run)
    {
        echo "UPDATED";
        header("Location: orders.php");
    }
    else
  {
        echo "NOT UPDATED";
   }
    
    
    }
    ?>

This code works but updates all the data in orders table as the current update doesnt update the specific selected order.

Please help me

CodePudding user response:

you have to use WHERE instead of WHEN in your query.

  • Related