Jump to content

search update delete record in mysql table using a form


hance2105
Go to solution Solved by hance2105,

Recommended Posts

hello all, 

 

i have a form named del_prod.php containing a search delete and update button. i want to know

  • how i can perform my search by inserting the product id in the product id field and related record is displayed in the textfields in the form.
  • delete the record from mysql table
  • update the record as well

this is my del_prod.php page code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Product</title>
 
<link href="CSS/del_prod.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
 
<div id="stylized" class="myform">
 
<form id="form" name="del_prod" method="post" action="delprod.php">
 
<h2 align="center"><b>- Delete / Update Product -</b></h2>
 
<table width="1000" border="0">
  <tr>
    <td><div align="right">Product ID</div></td>
    <td><input type="text" name="prod_id" id="prod_id"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Name</div></td>
    <td><input type="text" name="prod_name" id="prod_name" /></td>
  </tr>
  <tr>
    <td><div align="right">Product Brand</div></td>
    <td><input type="text" name="prod_brand" id="prod_brand"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Description</div></td>
    <td><textarea name="prod_desc" id="prod_desc" cols="45" rows="5"></textarea></td>
  </tr>
  <tr>
    <td><div align="right">Product Price (MRU)</div></td>
    <td><input type="text" name="prod_price" id="prod_price"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Category</div></td>
    <td><input type="text" name="cat" id="cat"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Subcategory</div></td>
    <td><input type="text" name="subcat" id="subcat"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Weight/Capacity</div></td>
    <td><input type="text" name="prod_w_c" id="prod_w_c"/></td>
  </tr>
  <tr>
    <td><div align="right">Uploaded Photo Path</div></td>
    <td><input type="text" name="prod_photo" id="prod_photo"/></td>
  </tr>
</table>
 
<p align="center">
  <input type="submit" class="button" name="search" id="search" value="<-- Search -->" />
  <input type="submit" class="button" name="delete" id="delete" value="<-- Delete product -->" />
  <input type="submit" class="button" name="update" id="update" value="<-- Update product -->" />
</p>
 
</form>
 
</div>
 
</body>
</html>
Link to comment
Share on other sites

i managed to sort out the search issue by using below code....but now can i hv the codes to delete the record or update it?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Product</title>
 
<link href="CSS/del_prod.css" rel="stylesheet" type="text/css" />
 
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.prod_id.options[form.prod_id.options.selectedIndex].value;
//var description1=form.description.value;
self.location='del_upd_prod.php?prod_id=' + val;
//+'&description=' +description1;
}
 
</script>
 
</head>
 
<body>
 
<?php
 
include('db_connect.php');
 
@$prod_id=$_GET['prod_id'];
//@$description=$_GET['description'];
 
//$id = rtrim($_GET['id']);
 
$query=mysql_query("select prod_id from tbl_product");
 
$query1=mysql_query("select prod_name, prod_brand, prod_desc, prod_price, cat, subcat, prod_w_c, prod_photo from tbl_product where prod_id='$prod_id'");
 
$row=mysql_fetch_array($query1);
 
?>
 
<div id="stylized" class="myform">
 
<form id="form" name="del_prod" method="post" action="delupdprod.php">
 
<h2 align="center"><b>- Delete / Update Product -</b></h2>
 
<table width="1000" border="0">
  <tr>
    <td><div align="right">Product ID</div></td>
    <td>
    <?PHP 
 
echo "<select name='prod_id' onchange=\"reload(this.form)\"><option value=''>select one</option>";
while($row1 = mysql_fetch_array ($query)) { 
if($row1['0']==@$prod_id){echo "<option selected value='".$row1['0']."'>".$row1['0']."</option>";}
else{echo  "<option value=\"".$row1['0']."\">".$row1['0']."</option>";}
}
echo "</select>";
?>
    
    </td>
  </tr>
  <tr>
    <td><div align="right">Product Name</div></td>
    <td><input type="text" name="prod_name" id="prod_name" value = "<?PHP print $row['prod_name']; ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Brand</div></td>
    <td><input type="text" name="prod_brand" id="prod_brand" value = "<?PHP print $row['prod_brand']; ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Description</div></td>
    <td><textarea name="prod_desc" id="prod_desc" cols="45" rows="5"><?PHP print $row['prod_desc']; ?></textarea></td>
  </tr>
  <tr>
    <td><div align="right">Product Price (MRU)</div></td>
    <td><input type="text" name="prod_price" id="prod_price" value = "<?PHP print $row['prod_price'] ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Category</div></td>
    <td><input type="text" name="cat" id="cat" value = "<?PHP print $row['cat']; ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Subcategory</div></td>
    <td><input type="text" name="subcat" id="subcat" value = "<?PHP print $row['subcat']; ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Product Weight/Capacity</div></td>
    <td><input type="text" name="prod_w_c" id="prod_w_c" value = "<?PHP print $row['prod_w_c']; ?>"/></td>
  </tr>
  <tr>
    <td><div align="right">Uploaded Photo Path</div></td>
    <td><input type="text" name="prod_photo" id="prod_photo" value = "<?PHP print $row['prod_photo']; ?>"/></td>
  </tr>
</table>
 
<p align="center">
  <input type="submit" class="button" name="delete" id="delete" value="<-- Delete product -->" />
  <input type="submit" class="button" name="update" id="update" value="<-- Update product -->" />
</p>
 
</form>
 
</div>
 
</body>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.