I have some problem when want to update my value in database. There is no error shown. The page will ust redirect as indicated even when the value is not updated. This is the code for user to input..
echo "<td bgcolor='#FFFFFF'><input id='id' name='pro_id[]' type='text'></td>";
echo "<td bgcolor='#FFFFFF'><input id='name' name='pro_name[]' type='text'></td>";
echo "<td bgcolor=‘#FFFFFF’><input id='quan' name='pro_quan[]' type='text'></td>";
Below is the code for my insert value..
$query = "INSERT INTO product (username, pro_id, pro_name, pro_quan) VALUES ";
for ($i = 0; $i < count($_POST['pro_id']); $i++) {
$query .= " ('{$username}', '{$id[$i]}', '{$name[$i]}', '{$quan[$i]}'),";
}
$query = substr($query, 0, -1);
$result = mysqli_query($con, $query) or die(mysqli_error($con));
The insert code work fine. The value is inserted into the database.Below is my update code..
$sql = "SELECT * FROM product where username = '$username'";
foreach($_SESSION['product'] as $item)
{
$id = $item['pro_id'];
$name = $item['pro_name'];
$quan = $item['pro_quan'];
$sold = $item['pro_sold'];
$sql="UPDATE product SET pro_id='".$id."', pro_name='".$name."', pro_quan='".$quan."', pro_sold='".$sold."' WHERE username = '".$username."'";
}
$results=mysqli_query($con, $sql);
The value couldn't be updated. I have no idea what have gone wrong.So, any help will be appreciated.Thanks
WHERE clausein update query.