example from the Read.php
i gave my columns an orderby asc and desc in the read file, but before that the edit.php was working code was working correctly.
My Update (or edit) is only returning one record- the first record to be updated.- pic shows first record in DB.
the product ID will not be updateable in the final version, just in for testing… this is a custom page in the
admin section of a CMS.
What I have tried you name it, been messing with this for a day. Time for help TY.
The question , what is wrong with my code in edit.php , no matter what edit i press,
I only get the first record of the database returned with Product ID of 35.
edit.php:
<?php error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
include 'connect.php';
if(isset($_POST['btn_submit'])){
$sql ="update products set
products_quantity = '".$_POST['txt_quantity']."',
products_weight = '".$_POST['txt_weight']."',
products_price= '".$_POST['txt_price']."'
where products_id = '".$_POST['txt_id']."'
";
if(mysqli_query($con, $sql)){
header('Location:index.php');
}else{
echo "Error " .mysqli_error($con);
}
}
if(isset($_GET['id'])){
$sql = "SELECT products_id, products_quantity, products_weight, products_price
FROM products";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0){
($row = mysqli_fetch_assoc($result));
$id = $row['products_id'];
$quantity = $row['products_quantity'];
$weight = $row['products_weight'];
$price = $row['products_price'];
}
}
?>
<form action="" method="post">
<table>
<tr>
<td>Product ID</td>
<td><input name = "txt_id" value ="<?=$id?>"></td>
</tr>
<tr>
<td>Quantity</td>
<td><input name = "txt_quantity" value ="<?=$quantity?>"></td>
</tr>
<tr>
<td>Weight</td>
<td><input name = "txt_weight" value ="<?=$weight?>"></td>
</tr>
<tr>
<td>Price</td>
<td><input name = "txt_price" value ="<?=$price?>"></td>
</tr>
<tr>
<td><input type = "hidden" value ="<?=$id?>" name = "txt_id" ></td>
<td><input type="submit" name="btn_submit"></td>
</tr>
</table>
</form>