user3707504
user3707504

Reputation: 3

SQL:Change the record

##$query = "SELECT * FROM bookingdevice ";
$res = mysql_query($query);

echo "<table border=1><tr><td>BookingID</td><td>AccountID</td><td>ProductID</td><td>Product Name</td><td>Status</td></tr>";

while ($row = mysql_fetch_array($res)){
    echo "<tr>";
    echo "<td>".$row['bookingdeviceID']."</td>";
    echo "<td>".$row['memberaccid']."</td>";
    echo "<td>".$row['prodid']."</td>";
    echo "<td>".$row['prodname']."</td>";
    echo "<td>".$row['bookingstatus']."</td>";
    echo ("<td><input type=submit name=submit id=submit value=Update Status></td>");
    echo ("<td><input name=BookID type=hidden value=".$row["bookingdeviceID"].">");
    echo "</tr>";
    echo "</form>";
}
?>
</p>



##

$bookid = $_POST['BookID'];

    $sel_query = "SELECT * FROM bookingdevice WHERE bookingdeviceID ='".$bookid."'";
$sel_res = mysql_query($sel_query);
while ($row = mysql_fetch_array($sel_res)){
    $bookingstatus =$row['bookingstatus'];
    $prodid =$row['prodid'];
    $memberid=$row['memberaccid'];
}

$mem_query = "SELECT * FROM memberinfo WHERE memberaccid ='".$memberid."'";
$mem_res = mysql_query($mem_query);
while ($rows = mysql_fetch_array($mem_res)){
    $memberstatus =$rows['memberstatus'];

}   
if ($bookingstatus == "Normal" ){
$status_update = "UPDATE bookingdevice SET bookingstatus ='TakeOut' WHERE bookingdeviceID ='".$bookid."'";
$status_res = mysql_query($status_update);
echo "Update success!";
    echo "<meta http-equiv=refresh content=2;url=OrderSituation.php>";

}else if($bookingstatus == "TakeOut" and $memberstatus =="2" ){
    $status_update2 = "UPDATE bookingdevice SET bookingstatus ='Return' WHERE bookingdeviceID ='".$bookid."'";
$status_res2 = mysql_query($status_update2);

$sql = "UPDATE productinfo SET Quantity='1' WHERE prodid='".$prodid."'";
$sql_res = mysql_query($sql);

$upstatus_query = "UPDATE memberinfo set memberstatus = '0' WHERE memberaccid='".$memberid."'";
$upstatus_res = mysql_query($upstatus_query);

echo "Update success!";
    echo "<meta http-equiv=refresh content=2;url=OrderSituation.php>";

    }else if($bookingstatus == "TakeOut" and $memberstatus =="4" ){
    $status_update3 = "UPDATE bookingdevice SET bookingstatus ='Return' WHERE bookingdeviceID ='".$bookid."'";
$status_res3 = mysql_query($status_update3);

$sql = "UPDATE productinfo SET Quantity='1' WHERE prodid='".$prodid."'";
$sql_res = mysql_query($sql);

$upstatus2_query = "UPDATE memberinfo set memberstatus = '3' WHERE memberaccid='".$memberid."'";
$upstatus2_res = mysql_query($upstatus2_query);

echo "Update success!";
    echo "<meta http-equiv=refresh content=2;url=OrderSituation.php>";
}else if ($bookingstatus == "Return" ){
    echo "The device was return";
    echo "<meta http-equiv=refresh content=2;url=OrderSituation.php>";
}

?>##

here is the image http://s29.postimg.org/gn2aaxixx/image.jpg

I can only change the last record. When I click other button ,only the last record will change. EG. I want change the bookingid22 record,when i click the bookingid22 button,only can change the bookingid23 record,bookingid22 can not change..........How can i DO?I want to change the same colum same record,thx

Upvotes: 0

Views: 60

Answers (1)

jey batosay
jey batosay

Reputation: 46

try this :


--------------
--------------
while ($row = mysql_fetch_array($res)){
    echo '<form name="form_"'.$row['bookingdeviceID'].'" method="post">';
    echo "<tr>";
    echo "<td>".$row['bookingdeviceID']."</td>";
    echo "<td>".$row['memberaccid']."</td>";
    echo "<td>".$row['prodid']."</td>";
    echo "<td>".$row['prodname']."</td>";
    echo "<td>".$row['bookingstatus']."</td>";
    echo ("<td><input type=submit name=submit id=submit value=Update Status></td>");
    echo ("<td><input name=BookID type=hidden value=".$row["bookingdeviceID"].">");
    echo "</tr>";
    echo "</form>";
}
------------------
------------------

Adding one new line code below the while scope.

Upvotes: 1

Related Questions