Jump to content

Recommended Posts

The following code is from the form action code.  On my site, a user adds a new item, then goes to the next page to confirm the details with the option to edit and update their information.  The problem is, its not updating the information in the database.  The information is showing up in the form fine and referring to the correct item id but just not updating.

 

mysql_connect("localhost", "", "", "") or die(mysql_error());

mysql_select_db("store") or die(mysql_error());

$item_title = mysql_real_escape_string($_POST[title]);
$item_description = mysql_real_escape_string($_POST[description]);
$item_price = mysql_real_escape_string($_POST[price]);
$item_location = mysql_real_escape_string($_POST[location]);
$item_ship_to = mysql_real_escape_string($_POST[ship_to]);
$item_shipping_cost = mysql_real_escape_string($_POST[shipping_cost]);
$item_international = mysql_real_escape_string($_POST[international]);
$item_in_shipping = mysql_real_escape_string($_POST[in_shipping]);
$item_id =  mysql_real_escape_string($_POST[id]);
$username = $_SESSION['username'];

  

$sql="UPDATE product SET title='$item_title', description='$item_description', price='$item_price', 
location='$item_location', ship_to='$item_ship_to', shipping_cost='$item_shipping_cost', international='$item_international', 
in_shipping='$item_in_shipping' WHERE id = [$item_id]";

header("location:add_new_product3.php?id={$item_id}=username=".$_SESSION['username']."");

if (!mysql_query($sql))

  {

  die('Error: ' . mysql_error());

  } 

 

Any suggestions??  I've been really stuck on this! Thanks!

Link to comment
https://forums.phpfreaks.com/topic/206915-update-problems/
Share on other sites

Because you are redirecting the page before it has a chance to run the mysql query?

 

 if (!mysql_query($sql))

  {

  die('Error: ' . mysql_error());

  }else {
    header("location:add_new_product3.php?id={$item_id}=username=".$_SESSION['username']."");
}

 

Should do the trick.

Link to comment
https://forums.phpfreaks.com/topic/206915-update-problems/#findComment-1082047
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.