I have a form for adding products and their detail to a mysql db. I have another form that shows the products where I can remove the product from the db, I can also hide or show the product in the website.
I need to be able to edite the product details too. Is there any way that when I choose to edit a products I can get it details to appear in the first form again? The form is for adding details so can it be used to edit them too?
This is my code for first product adding form.
<form class='productsaddform' action='productsadd.php' method='post' enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<?php
include '../inc/categorydropdown.php';
?>
<span class='formheading'>Add Product</span><br /><br />
<p><b>Choose Image</b><br /><input name="image_up />
<br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea><br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
<b>Price</b><br /><input type=text name="aprice" /><br />
<p><label for="cat">Category</label>
<select name="cat" id="cat">
<?php echo $op;?>
</select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="subcat"> </select></p>
<br />
<br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/add_products.php'; ?>
</form>
This is my second form, where i can clicked edit on a product
<form class='productsremoveform' action='productsadd.php' method='post'>
<?php include '../inc/categorydropdown.php'; ?>
<?php include '../inc/remove_products.php'; ?>
<span class='formheading'>Remove/Hide/Show Products</span><br /><br />
<p><label for="cat">Category</label>
<select name="cat" id="removecat"> <?php echo $op;?> </select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="removesubcat"> </select>
<input type='submit' name='show' value='Show' /> </p>
<?php
include '../inc/connect.php';
if(isset($_POST['show'])){
$subcat = intval($_POST['subcat']);
$q = "SELECT * FROM products WHERE subcat = $subcat";
$result = $link->query($q);
if($result){
while($row=mysqli_fetch_array($result)){
echo "<div class='removeproducts'>";
echo "<input type='checkbox' name='remove[{$row['id']}]'>Remove";
echo "<br />";
if ($row['status'] == 1){
echo"<input type='checkbox' name='hide[{$row['id']}]'>Hide";
echo "<br />";
}
if ($row['status'] == 2){
echo"<input type='checkbox' name='show[{$row['id']}]'>Show";
echo "<br />";
}
echo "<input type='submit' name='edit[{$row['id']}]' value='Edit'>";
echo "<br />";
echo "<br />",
"<span class='productthumbcode'>",
"{$row['code']}",
"</span>",
"<div id='thumb'>",
"<img class='resizedimage' src='{$row['image']}' alt='{$row['name']}' />",
"</div>",
"</div>";
}
echo "<br style='clear:both' />";
}
else{
echo mysqli_error();
}
}
?>
<input type='submit' id='submit' name='submit' value='Submit' />
</form>
And this is the code to be used when edit is clicked.
if(isset($_POST['edit'])){
$chk = (array) $_POST['edit'];
$p = implode(',',array_keys($chk));
$t = "SELECT * FROM products WHERE id IN ($p)";
$result = $link->query($t);
$url=mysqli_fetch_array($result);
}
Anyone able to help me out?
Thanks