kikilahooch Posted September 2, 2006 Share Posted September 2, 2006 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 workingif (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] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Looks like your query is failing. Change this:[code]$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>'; }[/code]To this:[code]$result = @mysql_query($query2) or die("Unable to perform query <code>" . $query2 . "</code><br /><br />" . mysql_error());echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';[/code]You should now get an error returned from MySQL why your query is failing. POst the error you get here. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 I thort and i was always told that when you start to hide @ errors then your heading for more problams.always echo all query's out to see if the data within the query is what it suppose to be good luck. Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 Thanks, when I did that it said:Unable to perform query 1You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 OMG, I should of spotted this earlier but you have already ran the query. The $query2 variable holds the result of the query, then you run $query2 through mysql_query again! Have a look at the code below:[code=php:0]// Youa re running the query here$query2 = mysql_query("UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'");// Here you pass $query2 to run the query. // But $query 2 alleady holds the result of the query$result = @mysql_query($query2);[/code]So use this instead for $query2:[code]$query2 = UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 afther all i just done dam didnt see that my self[code]$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>'; } [/code] Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 ok when I did what wildteen said it still deletes the prodname but it gives the message of UPDATED SUCCESSFULLY rather than System Error which it was doing before. Just to make sure I was getting you right I'll put up that part of the code again (Really dont know what I'm doing so I could be messing up your simple instructions!lol)[code]$query2 = "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) or die("Unable to perform query <code>" . $query2 . "</code><br /><br />" . mysql_error());echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 have a look at this i change all the query names as you was running to meny querys with the same name here you go.also added all the die for the querys and also took away the mysql_close as it's not needed.emample only not tested.[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 workingif (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'); $query1 = mysql_query("UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'"); $result1 = @mysql_query($query1)or dir("query 1"); if($result1){ echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>'; } else{ echo'<h1> System Error </h1>'; } $query2 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'"; $result2 = @mysql_query($query)or dir("query 2"); if($result2){ 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($result2, 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']; $query3 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'"; $result3 = @mysql_query($query3)or die("query 3"); if($result3){ 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($result3, 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(); } } ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 Thanks Redarrow :) I did that now. While I was updating it I also noticed that I had my form action wrong. I had it as admin_update.php when it should have been admin_update2.php. Now when I click on an image it no longer displays the table, it just says "query1" Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 it be better if you echo all the querys out ok.echo $query1;under query1echo $query2;under query2echo $query3;under query3when you look on the page your see the select staement and this should be the correct order as inteneded so good luck. Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 ok now it just displays1query 1Sorry If I'm being dumb here but really havent a clue of php and have to get this in soon! Really appreciate both your help!its also still deleting the prodName btw Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Try this:[code]<?php#Script 7.3 - register.phpinclude "db.php";$prodId = 0; // UPDATED$prodId = isset($_GET['prodId']) && is_numeric($_GET['prodId']) ? $_GET['prodId'] : 'INVALID';if($prodid == 'INVALID'){ die('<h1>Invalid Production Identification</h1>');}$sql = "SELECT * FROM product WHERE prodId=$prodId";$result = mysql_query($sql, $conn) or die(mysql_error()); //comment out if not workingif (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'); $query1 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'"; $result = @mysql_query($query1) or die("Unable to perform query1 <code>" . $query1 . "</code><br /><br />" . mysql_error()); echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>'; $query2 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'"; $result2 = @mysql_query($query) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error()); 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($result2, 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> <tr> <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td> <td align="left">' . $row['shopName'] . '</td> </tr> <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> <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> <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 align="center"> <p><input type="submit" name="submit" value="UPDATE"/> <input type="reset" value="CLEAR FORM"></p> <input type="hidden" name="prodId" value=' . $prodId . '> <input type="hidden" name="shopName" value=' . $sName . '> <input type="hidden" name="submittedUpdate" value="TRUE"/> </td> </tr> </table> </center></form>';}if(isset($_POST['submitted'])){ $prodId = trim($_POST['prodId']); $shopName= $_GET['shopName']; $query3 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'"; $result3 = @mysql_query($query3) or die("Unable to perform query3 <code>" . $query3 . "</code><br /><br />" . mysql_error()); 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($result3, 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> <tr> <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td> <td align="left">' . $row['shopName'] . '</td> </tr> <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> <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> <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 align="center"> <input type="submit" name="submit" value="UPDATE"/> <!--<input type="reset" value="CLEAR FORM"></p>--> </td> </tr> <tr> <td align="center"> <input type="hidden" name="prodId" value=' . $prodId . '> <input type="hidden" name="shopName" value=' . $shopName . '> <input type="hidden" name="submittedUpdate" value="TRUE"/> </td> </tr> </table> </center></form>';}?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 give this a quick go okback up your existing work is this is classed as an example of you current work thank you.[code]<?php #Script 7.3 - register.phpinclude "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 workingwhile ($record=mysql_fetch_assoc($result)){$prodId=$record['prodid'];$shopName=$record['shopname'];$dept=$record['dept'];$brand=$record['brand'];$type=$record['type'];$image=$record['image'];$price=$record['price'];if (mysql_num_rows($result) == 1) {$query1 = mysql_query("UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'"); $result1 = @mysql_query($query1)or dir("query 1");if($result1){echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';}else{echo'<h1> System Error </h1>';} $query2 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'";$result2 = @mysql_query($query)or dir("query 2"); if($result2){ 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($result2, 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']; $query3 = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'"; $result3 = @mysql_query($query3)or die("query 3"); if($result3){ 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($result3, 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] Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 Thanks! Now its saysUnable to perform query2 SELECT * FROM product WHERE prodId = '2' and shopName='savage'Query was empty Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Oops missed typed something Change this line:[code]$result2 = @mysql_query($query) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error());[/code]to this:[code]$result2 = @mysql_query($query2) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 was that wildteens code or mine with the problam probly me lol...........? Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 When I tried yours (redarrow) it came up with 1query1,Wildteens came up withUnable to perform query2 SELECT * FROM product WHERE prodId = '106' and shopName='savage'Query was empty Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 kikilahooch Did you try the correction I suggested in my last post?[quote author=wildteen88 link=topic=106622.msg426669#msg426669 date=1157221176]Oops missed typed something Change this line:[code]$result2 = @mysql_query($query) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error());[/code]to this:[code]$result2 = @mysql_query($query2) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error());[/code][/quote] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 2, 2006 Share Posted September 2, 2006 wildteen when your finished can you kindly exsplain this code to me as i never in my life seen it done like this cheers m8$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'); Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 Sorry I just copied and pasted it. I changed it to $query2 now. Its back to saying Updated Successfully and deletes the prodName Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 In query1:[b]UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price'WHERE prodId ='$prodId' and shopName='$shopName'[/b]You use $prodName to update the prodName field. Where does $prodName come from, as this is mostl ikey why it is being [b]deleted[/b] as $prodName doesnt exist[b]To redarrow[/b] -mysql_result is basically another form of retrieve results from an SQL Query. I have not used this before so I cant really explain it. Have a read in the manual about it http://php.net/mysql-query Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 Aaah I'm stupid! That has solved the deleting problem! Thanks Wildteen!! Now when I try to update something it says:Unknown column 'INVALID' in 'where clause' Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Oh crap. Another typo of mine.Change this:[code]$prodId = isset($_GET['prodId']) && is_numeric($_GET['prodId']) ? $_GET['prodId'] : 'INVALID';if($prodid == 'INVALID'){ die('<h1>Invalid Production Identification</h1>');}[/code]to this:[code]$prodId = isset($_GET['prodId'])) ? $_GET['prodId'] : '0'[/code] Quote Link to comment Share on other sites More sharing options...
kikilahooch Posted September 2, 2006 Author Share Posted September 2, 2006 ok so I changed the code to that[code]$prodId = 0; // wasnt sure if this was to be left in but it doenst seem to make any difference when I take it out$prodId = isset($_GET['prodId']) ? $_GET['prodId'] : '0'$sql = "SELECT * FROM product WHERE prodId=$prodId";// line 77[/code]now it says Parse error: parse error, unexpected T_VARIABLE in /home/c/ciaracousins/public_html/admin_update2.php on line 77 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 2, 2006 Share Posted September 2, 2006 Sorry, I am not being very alert today. Use this:$prodId = isset($_GET['prodId']) ? $_GET['prodId'] : '0';I forgot the semi-colon, at the end of the line. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.