i ma having problem with the code plz help me someone
the code is like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
include_once "connection.php";
$cat_id=$_REQUEST['cat_id'];
if(isset($_POST['update_data']) && ($_POST['update_data']=='update'))
{
if(isset($_POST['Edit']) && ($_POST['Edit']=='Edit Product'))
{
if($_POST['cat_name']!='' && $_POST['comp_name']!='' && $_POST['mode1']!='' && $_POST['prod_desc']!='' && $_POST['rate']!='')
{
$cat_name=$_POST['cat_name'];
$prod_name=stripslashes(trim($_POST['prod_name']));
$select_catagory2="select * from tblcatagory where cat_name='".$cat_name."'";
$select_qury2=mysql_query($select_catagory2) or die(mysql_error());
$result_cat_id=mysql_fetch_object($select_qury2);
$cat_id=$result_cat_id->cat_id;
$comp_name=stripslashes(trim($_POST['comp_name']));
$model=stripslashes(trim($_POST['model']));
$prod_desc=stripslashes(trim($_POST['prod_desc']));
$rate=stripslashes(trim($_POST['rate']));
$insert_query="update tblproduct set cat_id='$cat_id',comp_name='$comp_name',model='$model',prod_desc='$prod_desc',rate='$rate' where prod_id='".$_REQUEST['prod_id']."'";
$result=mysql_query($insert_query) or die(mysql_error());
if($result)
{
$msg1="product Info Update!!";
}
}
}
}
if(isset($_POST['update_picture']) && ($_POST['update_picture']=='update_picture'))
{
if(isset($_POST['Edit_Pic']) && ($_POST['Edit_Pic']=='Change PIcture'))
{
$img_name=$_FILES['file']['name'];
$img_tmp_name=$_FILES['file']['tmp_name'];
$prod_img_path=time().img_name.'.jpg';
if($img_name!='')
{
$select_img="select * from tblproduct where prod_id='".$_REQUEST['prod_id']."'";
$qry=mysql_query($select_img) or die(mysql_error());
$res=mysql_fetch_object($qry);
if(file_exists("img/".$res->prod_img_path))
{
unlink("img/".$res->prod_img_path);
}
move_uploaded_file($img_tmp_name,"img/".$prod_img_path);
$insert_query="update tblproduct set prod_img_path='$prod_img_path' where prod_id='".$_REQUEST['prod_id']."'";
$result=mysql_query($insert_query) or die(mysql_error());
if($result)
{
$msg2="Picture Updated";
}
}
}
}
$query="select * from tblproduct where prod_id='".$_REQUEST['prod_id']."'";
$result=mysql_query($query) or die (mysql_error());
$data=mysql_fetch_object($result);
$select_catagory="select * from tblcatagory";
$select_query_catagory=mysql_query($select_catagory) or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Update Products</title>
</head>
<body>
<h2 align="center">Edit Products Details</h2>
<hr align="center" size="4" color="#990000" width="328"/>
<h3 align="center"><span><?php echo $msg1?></span></h3>
<table width="100%" border="0">
<tr><td width="22%">
<table width="100%" border="0">
<tr>
<td align="center"><a href="AddCatagory.php">Add New Catagory</a></td></tr>
<tr>
<td align="center"><a href="DisplayCatagories.php">Display Catagories</a></td></tr>
<tr> <td align="center"><a href="DisplayProducts.php">Display Products</a></td></tr>
<tr><td align="center"><a href="index.php">Main Page</a></td></tr></table></td>
<td width="78%">
<form name="frm" method="post" enctype="multipart/form-data">
<input type="hidden" name="update_data" value="update_data"/>
<table width="623" border="0" align="center" cellspacing="5">
<tr>
<td>Product Name:</td>
<td>
<input type="text" name="prod_name" value="<?php echo $data->prod_name?>"/></td>
</tr>
<tr>
<td> catagory:</td>
<td>
<select name="cat_name"><?php while($data_catagory=mysql_fetch_object($select_query_catagory))
{
?>
<option value="<?php echo $data_catagory->cat_name?>"<?php if($data_catagory->cat_name==$cat_name){echo 'selected';
}
?>> <?php echo $data_catagory->cat_name?></option><?php } ?>
</select></td></tr>
<tr>
<td> Company Name:</td><td><input type="text" name="comp_name" value="<?php echo $data->comp_name?>"/>
</tr>
<tr>
<td> Model:</td>
<td><input type="text" name="model" value="<?php echo $data->model?>"/></td>
</tr>
<tr>
<td>Product Description:</td>
<td><input type="text" name="prod_desc" value="<?php echo $data->prod_desc?>"/></td>
</tr>
<tr>
<td> Rate:</td>
<td><input type="text" name="rate" value="<?php echo $data->rate?>"/></td></tr>
</table>
<table width="564" border="0" align="center" cellspacing="5">
<tr>
<td align="center"><input type="submit" name="Edit" value="Edit Product"/></td></tr></table></form>
<br/>
<br/>
<h2 align="center">Change product Pciture</h2>
<hr align="center" size="4" color="#9900000" width="368"/>
<h3 align="center"><span><?php echo $msg2?></span></h3>
<form method="post" name="frm2" enctype="multipart/form-data">
<input type="hidden" name="update_picture" value="update_picture"/>
<table width="623" border="0" align="center" cellspacing="5">
<tr>
<td width="218">Change Picture:</td>
<td width="380"><input type="file" name="file"/></td></tr></table>
<br/>
<div align="center"><input type="submit" name="Edit_Pic" value="Change Picture"/></div></form></td>
</td></tr></table>
</body>
</html>
plz help me to update database
Moderator: General Moderators
Re: plz help me to update database
It would be very helpful if you actually told us what the problem is with the code. No one is going to look through all of that just to find out what the problem is. You've got to give us something to go on.
Re: plz help me to update database
data is not being updated with the above code
Re: plz help me to update database
That's not enough information. Please be more detailed. What error messages are you getting? Describe the situation.
Read some other posts on this forum and look at the detail provided. You're only going to get help if you provide detail.
I realize your english isn't that good but that's ok, but we're not going to do all the work for you. You have to give us more information.
Read some other posts on this forum and look at the detail provided. You're only going to get help if you provide detail.
I realize your english isn't that good but that's ok, but we're not going to do all the work for you. You have to give us more information.
Re: plz help me to update database
when ever i tried to update the data with new data.the same page is reload without any error or anything wrong or any change.neither the data is updated nor shown any type of error details.i m so confused wat is going on with the code.
Re: plz help me to update database
At the end of your queries, add OR die(mysql_error();
For example:
For example:
Code: Select all
$qry = mysql_query("SELECT * FROM table") or die(mysql_error());