Jump to content

newbie help updating records


kikilahooch

Recommended Posts

Hi, I have a page where i want to be able to update records stored in my database. What I am doing is I first have a list of all products with images displayed beside them. To update a record I click on an image and this then brings me to a page called admin_update2.php. What should happen here is that a table filled with all of the details of the product clicked on appears. The fields stored on each product are:

prodId int(10)
shopName varchar(30)
prodName varchar(40)
dept varchar(20)
brand varchar(20)
type varchar(20)
image varchar(60)
price double(3,2)
NoInStock int(3)

The fields prodId and shopName are not editable because these will always stay the same. What happens when I click on an image is the table appears with all of the values on the product showing apart from prodName (which is the 1st field which can be updated). prodName gets deleted when I click on the image and a message saying "system error" appears.

Can anybody help me with this pls. Newbie with a deadline here!!

[code]
<?php #Script 7.3 - register.php
include "db.php";



$prodId = 0;  // UPDATED
$prodId = $_GET['prodId'];


$sql= "select * from product where prodId=$prodId";


$result = mysql_query($sql,$conn) or die(mysql_error()); //comment out if not working

if (mysql_num_rows($result) == 1) {

//if authorized, get the values of prodId, shopName...

$prodId = mysql_result($result, 0, 'prodId');
$shopName = mysql_result($result, 0, 'shopName');
$dept = mysql_result($result, 0, 'dept');
$brand = mysql_result($result, 0, 'brand');
$type = mysql_result($result, 0, 'type');
$image = mysql_result($result, 0, 'image');
$price = mysql_result($result, 0, 'price');



$query2 = mysql_query("UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'");

$result = @mysql_query($query2);
if($result){
echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';
}

else{
echo'<h1> System Error </h1>';
}



$query = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'";


$result = @mysql_query($query);
if($result){
echo'


<form action="admin_update2.php" method="post">



<center>
<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">';

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo'


<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Id </b></center></td>
<td align="left">'.$row['prodId'].'</td>




<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td>
<td align="left">'.$row['shopName'].'</td>

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Name</b></td>
<td align="left"><input type="text" name="prodName" size="30" maxlength="30" value="'.$row['prodName'].'"/></td>

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Department</b></td>
<td align="left"><input type="text" name="dept" size="20" maxlength="20" value="'.$row['dept'].'"/></td>

.....

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Price</b></td>
<td align="left"><input type="text" name="price" size="50" maxlength="50" value="'.$row['price'].'"/></td>



</tr>';
}
echo'


<tr><td><center><input type="submit" name="submit" value="UPDATE"/>
<input type="reset" value="CLEAR FORM"></p></center>


<input type="hidden" name="prodId" value='.$prodId.'>
<input type="hidden" name="shopName" value='.$sName.'>



<input type="hidden" name="submittedUpdate" value="TRUE"/></form></td></tr>

</table>

';
}

}

if(isset($_POST['submitted'])){

$prodId = trim($_POST['prodId']);
$shopName= $_GET['shopName'];





$query = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'";




$result = @mysql_query($query);
if($result){
echo'


<form action="admin_update.php" method="post">



<center>
<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">';

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo'


<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Id</b></center></td>
<td align="left">'.$row['prodId'].'</td>



<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td>
<td align="left">'.$row['shopName'].'</td>

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Name</b></td>
<td align="left"><input type="text" name="prodName" size="30" maxlength="30" value="'.$row['prodName'].'"/></td>

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Department</b></td>
<td align="left"><input type="text" name="dept" size="20" maxlength="20" value="'.$row['dept'].'"/></td>

.....

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Price</b></td>
<td align="left"><input type="text" name="price" size="50" maxlength="50" value="'.$row['price'].'"/></td>





</tr>';
}
echo'


<tr><td><center><input type="submit" name="submit" value="UPDATE"/>
<!--<input type="reset" value="CLEAR FORM"></p></center>-->
<tr><td><center>



<input type="hidden" name="prodId" value='.$prodId.'>
<input type="hidden" name="shopName" value='.$shopName.'>



<input type="hidden" name="submittedUpdate" value="TRUE"/></form></td></tr>

</table>
';

}

else{
echo'<h1> System Error1 </h1> table ';
exit();
}

}
mysql_close();

?>



</body>
</html>
[/code]
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.