Jump to content

Recommended Posts

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>&nbsp<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>";

?>

Link to comment
https://forums.phpfreaks.com/topic/88100-solved-updating-product/
Share on other sites

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

$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!

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

 

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.