Technosoft Patel
Technosoft Patel

Reputation: 37

mysqli_query of update statement isn't working in PHP

I have written code with an update statement but it doesn't affect the database. I have tried with and without single quotes but it still doesn't update the database. I have by default value of Details="Order Placed" in the table but when I update the value with the update query it doesn't work.

<?php
include("connection1.php")
?>

<form method="POST">
Enter Orderid to be updated<br>
<input type="text" name="id">
<br>
<input type="radio" id="m" name="info" value="placed">
<label for="m">Order Placed</label><br>
<input type="radio" id="f" name="info" value="shipped">
<label for="f">Order Shipped</label><br>
<input type="radio" id="o" name="info" value="Delivered">
<label for="o">Order Delivered</label>
<input type="submit" name="submit" value="submit">
</form>

<?php
if(isset($_POST['submit']))
{
 $i=$_POST['id'];
 $info1=$_POST['info'];
 $query=("SELECT * FROM shipments WHERE OrderId='$i'");
 $data=mysqli_query($conn, $query);
 $total=mysqli_num_rows($data);
 if($total==1)
 {
  $query1=mysqli_query("UPDATE `shipments` SET `Details`='$info1 
  WHERE`OrderId`='$i'");
        if($result==mysqli_query($conn, $query1))
        {
            echo "ORDER UPDATED";
        }
        else
        {
            echo "ORDER NOT UPDATED";
        }

    }       
}

?> 

enter image description here

Upvotes: 0

Views: 128

Answers (1)

Antony Jack
Antony Jack

Reputation: 480

Just remove unwanted mysqli_query in Update statement $query1...

Change

$query1=mysqli_query("UPDATE `shipments` SET `Details`='$info1 
  WHERE`OrderId`='$i'");

To

$query1= "UPDATE shipments SET Details ='$info1' WHERE OrderId='$i'";

Upvotes: 1

Related Questions