0

I really don't understand why this simple task has to be so complicated. I am trying to UPDATE the mysql database and no matter what I do, it doesn't update it!

I keep getting this Notice message as well..

Notice: Undefined index: thisID in

basically i get all the values echo-ed in the fields properly but I cannot update the mysql when i press the submit button and i get the error above!

I parse the info/data like so from listing.php

<?php 
// This block grabs the whole list for viewing
$product_list = "";
$sql = "SELECT * FROM products ORDER BY date_added DESC";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query); // count the output amount
if ($productCount > 0) {
    while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $quantity = $row["quantity"];
             $shipping = $row["shipping"];
             $category = $row["category"];
             $manufactor = $row["manufactor"];
             $special = $row["special"];
             $stock = $row["stock"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
             $product_list .= "Product ID: $id - <strong>$product_name</strong> - £$price - <em>Added $date_added</em> &nbsp; &nbsp; &nbsp; <a href='edit.php?pid=$id'>edit</a> &bull; <a href='listing.php?deleteid=$id'>delete</a><br />";
    }
} else {
    $product_list = "You have no products listed in your store yet";
}
?>

and this is the EDIT page edit.php

<?php 
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {

      $pid = mysqli_real_escape_string($db_conx, $_POST['thisID']);
    $product_name = mysqli_real_escape_string($db_conx, $_POST['product_name']);
    $price = mysqli_real_escape_string($db_conx, $_POST['price']);
    $quantity = mysqli_real_escape_string($db_conx, $_POST['quantity']);
    $shipping = mysqli_real_escape_string($db_conx, $_POST['shipping']);
    $category = mysqli_real_escape_string($db_conx, $_POST['category']);
    $manufactor = mysqli_real_escape_string($db_conx, $_POST['manufactor']);
    $special = mysqli_real_escape_string($db_conx, $_POST['special']);
    $stock = mysqli_real_escape_string($db_conx, $_POST['stock']);
    $details = mysqli_real_escape_string($db_conx, $_POST['details']);
    // See if that product name is an identical match to another product in the system
    $sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details', WHERE id=$pid";
    if (!$sql) {
    echo mysqli_errno($db_conx) . ": " . mysqli_error($db_conx) . "\n";
    die();
}
    $query = mysqli_query($db_conx, $sql);
    header("location:");
    exit();
}
?>

could someone please shed a light on this for me?

Thanks in advance.

2
  • make sure you have the value thisID on your form $_POST['thisID'] Commented Jan 26, 2014 at 14:07
  • @MarCejas, done and done. your suggestion with the answer bellow did the trick! nice one :) Commented Jan 26, 2014 at 14:16

1 Answer 1

5

You've got an extra comma before your `WHERE clause:

$sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details', WHERE id=$pid";

Just remove it, and you should be fine:

$sql = "UPDATE products SET product_name='$product_name', price='$price', quantity='$quantity', shipping='$shipping', category='$category', manufactor='$manufactor', special='$special', stock='$stock', details='$details' WHERE id=$pid";
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but still doesn't update the mysql database and I still get the Notice message Notice: Undefined index: thisID.
Great. I also had to follow @MarCeja's suggestion above and everythings fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.