hbalagh Posted January 27, 2008 Share Posted January 27, 2008 I have this script that isn't updating the products when i change something... was wondering if someone can assist me w this <?php include("../includes/db.conf.php"); include("../includes/connect.inc.php"); echo "<html><body bgcolor='#cccccc'><font face='verdana'><center>"; if (isset($_GET['cat'])){ $query = "SELECT * from products where category='$_GET[cat]' "; $mysqlresult = mysql_query($query); $queryc=mysql_query("select * from categories where id='$_GET[cat]' "); $rowqueryc=mysql_fetch_array($queryc); echo "<h2>$rowqueryc[name]</h2>"; echo "<table border=1 width=75%>"; while($row = mysql_fetch_array($mysqlresult)){ echo "<tr><td><a href='product.php?pro=$row[id]'>$row[name]</a></td><td><a href='product.php?ed=$row[id]'>Edit</a></td><td><a href='product.php?del=$row[id]'>Delete</a></td></tr>"; } echo "</table>"; }elseif(isset($_GET['pro'])){ $query = "SELECT * from products where id='$_GET[pro]' "; $mysqlresult = mysql_query($query); echo mysql_error(); echo "<table border=1 width=50%>"; while($row = mysql_fetch_array($mysqlresult)){ echo "<tr><td colspan=2><b>$row[name]</b></td></tr>\n"; echo "<tr><td valign='top' width=75%>$row[description]</td><td><img src='../images/thumbs/$row[photo]'></td>\n"; echo "<tr><td>Price:$row[price]</td><td>Shipping:$row[shipping]</td><td>Quantity:$row[quantity]</td></tr>\n"; } echo "</table>"; }elseif(isset($_GET['ed'])){ $query = "SELECT * from products where id='$_GET[ed]' "; $mysqlresult = mysql_query($query); echo mysql_error(); while($row = mysql_fetch_array($mysqlresult)){ echo "<form action='product.php' method='post' enctype='multipart/form-data'> "; echo "<table>"; echo "<tr><td>Product Name</td>"; echo "<td><input name='pname' type='text' size='25' value='$row[name]' /></td></tr>"; echo "<tr><td colspan=2>Description</td></tr>"; echo "<tr><td colspan=2><textarea name='description' cols='30' rows='5'> $row[description]</textarea></td></tr>"; echo "<tr><td>Price</td>"; echo "<td><input type='text' name='price' value='$row[price]'></td></tr>"; echo "<tr><td>Shipping (Amount to charge per item)</td>\n"; echo "<td><input name='shipping' type='text' size='6' value='$row[shipping]' /></td></tr>\n"; echo "<tr><td>Category</td>"; echo "<td><select name='category'>"; $query2 = "SELECT * from categories "; $mysqlresult2 = mysql_query($query2); while($row2 = mysql_fetch_array($mysqlresult2)){ echo "<option value='$row2[id]' "; if ($row2['id']==$row['category']){echo "selected";} echo ">$row2[name]</option>"; } echo "<select></td></tr>"; echo "<tr><td>Quantity</td>"; echo "<td><input type='hidden' name='id' value='$row[id]'><input type='text' name='quantity' value='$row[quantity]'></td></tr>"; echo "<tr><td colspan=2><input type='submit' name='submit' value='Submit'></td></tr>"; echo "</table>"; } }elseif(isset($_POST['submit'])){ $queryn="update products set name='$_POST[pname]', description='$_POST[description]', price='$_POST[price]', shipping='$_POST[shipping]', category='$_POST[category]', quantity='$_POST[quantity]' where id='$_POST[id]'"; $mysqlresultn = mysql_query($queryn); echo "Product Updated"; }elseif(isset($_GET['del'])){ $query = "SELECT * from products where id='$_GET[del]' "; $mysqlresult = mysql_query($query); while($row = mysql_fetch_array($mysqlresult)){ echo "Do you want to delete this product?<br>$row[name]<br>"; echo "<a href='product.php?del2=$row[id]'>Yes</a> <a href='product.php?pro=$row[id]'>No</a>"; } }elseif(isset($_GET['del2'])){ $query = "delete from products where id='$_GET[del2]' "; $mysqlresult = mysql_query($query); echo "Product Deleted"; }else{ $query = "SELECT * from categories "; $mysqlresult = mysql_query($query); echo "<h2>Categories</h2>\n"; echo "<table>"; while($row = mysql_fetch_array($mysqlresult)){ echo "<tr><td><a href='product.php?cat=$row[id]'><b>$row[name]</a></td></tr>\n"; } echo "</table>"; } echo "</body></html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/ Share on other sites More sharing options...
teng84 Posted January 27, 2008 Share Posted January 27, 2008 try something like this first $queryn="update products set name='{$_POST[pname]}', description='{$_POST[description]}', price='{$_POST[price]}', shipping='{$_POST[shipping]}', category='{$_POST[category]}', quantity='{$_POST[quantity]}' where id='{$_POST[id]}'"; $mysqlresultn = mysql_query($queryn) or die(mysql_error(); if($mysqlresultn){ echo "Product Updated"; } then tell us what happen Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450748 Share on other sites More sharing options...
hbalagh Posted January 27, 2008 Author Share Posted January 27, 2008 gives me Parse error: syntax error, unexpected ';' in /home/china/public_html/mng/product.php on line 79 line 79 is $mysqlresultn = mysql_query($queryn) or die(mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450757 Share on other sites More sharing options...
teng84 Posted January 27, 2008 Share Posted January 27, 2008 sorry.. $mysqlresultn = mysql_query($queryn) or die(mysql_error());//i missed ) Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450770 Share on other sites More sharing options...
hbalagh Posted January 27, 2008 Author Share Posted January 27, 2008 now getting ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id='181'' at line 7 after i try to submit Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450789 Share on other sites More sharing options...
teng84 Posted January 27, 2008 Share Posted January 27, 2008 $queryn="update products set `name`='{$_POST['pname']}', `description`='{$_POST['description']}', `price`='{$_POST['price']}', `shipping`='{$_POST['shipping']}', `category`='{$_POST['category']}', `quantity`='{$_POST['quantity']}' where `id`='{$_POST[id]}'"; $mysqlresultn = mysql_query($queryn) or die(mysql_error()); if($mysqlresultn){ echo "Product Updated"; } try! Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450793 Share on other sites More sharing options...
hbalagh Posted January 28, 2008 Author Share Posted January 28, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/china/public_html/mng/product.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450829 Share on other sites More sharing options...
teng84 Posted January 28, 2008 Share Posted January 28, 2008 if (isset($_GET['cat'])){ $query = "SELECT * from products where category='{$_GET[cat]}' "; $mysqlresult = mysql_query($query) or die (mysql_error()); $queryc=mysql_query("select * from categories where id='{$_GET[cat]}' ")or die (mysql_error());; $rowqueryc=mysql_fetch_array($queryc); echo "<h2>".$rowqueryc[name]."</h2>"; echo "<table border=1 width=75%>"; while($row = mysql_fetch_array($mysqlresult)){ echo "<tr><td><a href='product.php?pro=$row[id]'>".$row[name]."</a></td><td><a href='product.php?ed=".$row[id]."'>Edit</a></td><td><a href='product.php?del=".$row[id]."'>Delete</a></td></tr>"; } men you have tons of error please edit your codes just the way i do it... that will sort your first error but i still found lots of error below so please edit it first just follow what i did in this post Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450835 Share on other sites More sharing options...
hbalagh Posted January 28, 2008 Author Share Posted January 28, 2008 thanks works now Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450849 Share on other sites More sharing options...
teng84 Posted January 28, 2008 Share Posted January 28, 2008 doest it sort your prob completely ? then mark this as solved Quote Link to comment https://forums.phpfreaks.com/topic/88100-solved-updating-product/#findComment-450850 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.