Hello all,
I am developing a basic admin dashboard with the feature of
Add item
Edit item
Delete item
Delete and Edit are compete but I need a small help. I am trying to display the time when the product was “last edited”.
Here is the code of the update form:
<?php
include('./server/class/mysql_crud.php');
if(isset($_GET['id'])) {
$db = new Database();
$db->connect();
// Table name, Column Names, JOIN, WHERE conditions, ORDER BY conditions
$db->select('products', 'id, name, description, price, datePosted, lastUpdated, creatorId', NULL);
//$db->select('products');
$res = $db->getResult();
//print_r($res);
foreach ($res as $key => $mushref) {
echo $mushref['id'];
echo $mushref['name'];
echo $mushref['description'];
echo $mushref['price'];
echo $mushref['datePosted'];
echo $mushref['lastUpdated'];
echo $mushref['creatorId'];
}
} else {
echo 'nope...';
}
?>
<form method="post" action="./server/update.php">
<!-- Content update -->
<input value="<?php echo $mushref['name']; ?>" name="name" />
<input type="text" value="<?php echo $mushref['description']; ?>" name="description" />
<input value="<?php echo $mushref['price']; ?>" name="price" />
<!-- things users mustn't edit -->
<input type="hidden" value="<?php echo $mushref['id']; ?>" name="id" />
<input type="hidden" value="<?php echo $mushref['datePosted']; ?>" name="datePosted" />
<input type="hidden" value="<?php echo $mushref['lastUpdated']; ?>" name="lastUpdated" />
<input type="hidden" value="<?php echo date($mushref['creatorId']); ?>" name="creatorId" />
<!-- Update button -->
<input type="submit" name="updateProduct" id="updateProduct" value="updateProduct" />
</form>
Code for the update function:
<?php
include('class/mysql_crud.php');
if( isset($_POST['updateProduct']) ) {
$productId = $_POST['id'];
$productName = $_POST['name'];
$productDesc = $_POST['description'];
$productPrice = $_POST['price'];
$datePosted = $_POST['datePosted'];
$lastUpdated = $_POST['lastUpdated'];
$db = new Database();
$db->connect();
// Table name, column names and values, WHERE conditions
$db->update('products', array(
'name' => "$productName",
'description' => "$productDesc",
'price' => "$productPrice",
'datePosted' => "$datePosted",
'lastUpdated' => "$lastUpdated"
), 'id="' . $productId . '"');
$res = $db->getResult();
//echo count($array);
if (count($res) == 0) {
echo "Couldnt be Updated";
} else {
echo "Successfully Updated";
}
//print_r($res);
}
?>
Now everything is working correctly, except the “lastUpdated”.
Please advise.
Thank you!