hello guys, i have 2 tables - tblproduct and tblretprod. prod_id is common in both. i am retrieving records from the tables to display with edit and delete options beside each record displayed.
i created an update.php and updprod.php (for edit).
update.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update/Delete Product</title>
<?php
include_once("db_connect.php");
$result=mysql_query("SELECT a.prod_name, a.prod_brand, b.prod_price FROM tblproduct a, tblretprod b where a.prod_id = b.prod_id");
?>
</head>
<body>
<?php
echo "<table width='80%' border=0>";
echo "<tr bgcolor='#CCCCCC'>";
echo "<td>Product</td>";
echo "<td>Brand</td>";
echo "<td>Price</td>";
echo "<td>Action</td>";
echo "</tr>";
while($res=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$res['prod_name']."</td>";
echo "<td>".$res['prod_brand']."</td>";
echo "<td>".$res['prod_price']."</td>";
echo "<td><a href=\"edit.php?prod_id=$res[prod_id]\">Edit</a> | <a href=\"delete.php?prod_id=$res[prod_id]\">Delete</a></td>";
}
echo "</table>";
?>
</body>
</html>
</body>
</html>
error message being displayed for code above is - notice: Notice: Undefined index: prod_id in C:\wamp\www\buysmart_site\update.php on line 36
upd_prod.php
include_once("db_connect.php");
if(isset($_POST['update']))
{
$prod_id = $_POST['prod_id'];
$prod_name=$_POST['prod_name'];
$prod_brand=$_POST['prod_brand'];
$prod_price=$_POST['prod_price'];
// checking empty field
if(empty($prod_price))
{
//if name field is empty
if(empty($prod_price))
{
echo "<font color='red'>Price field is empty.</font><br/>";
}
}
else
{
//updating the table
$result=mysql_query("UPDATE tblretprod SET proc_price='$prod_price' WHERE prod_id=$prod_id");
//redirectig to the display page. In our case, it is index.php
//header("Location: index.php");
}
}
?>
<?php
//for displaying data of this particular data
//getting id from url
$prod_id = $_GET['prod_id'];
//selecting data associated with this particular id
$result=mysql_query("SELECT a.prod_name, a.prod_brand, b.prod_price FROM tblproduct a, tblretprod b where a.prod_id = b.prod_id");
while($res=mysql_fetch_array($result))
{
$prod_name = $res['prod_name'];
$prod_brand = $res['prod_brand'];
$prod_price = $res['prod_price'];
}
?>
<html>
<title>Edit Product</title>
<body>
<a href="#">Home</a>
<br/><br/>
<form name="edit" method="post" action="edit.php">
<table border="0">
<tr>
<td>Product Name</td>
<td>
<input disabled="disabled" type="text" name="prod_name" value=<?php echo $prod_name;?>> </td>
</tr>
<tr>
<td>Brand</td>
<td>
<input disabled="disabled" type="text" name="prod_brand" value=<?php echo $prod_brand;?>> </td>
</tr>
<tr>
<td>Product Price</td>
<td>
<input type="text" name="prod_price" value=<?php echo $prod_price;?>> </td>
</tr>
<tr>
<td><input type="hidden" name="prod_id" value=<?php echo $_GET['prod_id'];?>> </td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>
same error message as above
can anyone please help me in defining the prod_id?