Updating script

please this update script not working
this is the script


require_once("include/session.php");
require_once("include/dataconnect.php");
require_once("include/functions.php");
//"<pre>";print_r($_POST); echo "</pre>";
if(array_key_exists('item', $_POST)){
    $items = $_POST['item'];

    //Loop through $_POST items, updating the database for each item
    foreach ($items as $item) {
        $Pquantity = intval($item[0]);
        $Pidno = intval($item[1]);
        $queryreg = mysql_query("
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       Uname = '{$_SESSION['username']}'
        ") or die(mysql_error());

this is the form


<?php

  // Output start of table and form
  echo "
    <form action='updatepplac.php' method='Post' class='slistbar'>
    <table border='1'>
      <tr>
        <th>SHOP NAME</th>
        <th>PRODUCT NAME</th>
        <th>PRODUCT SIZE</th>
        <th>PRODUCT COLOUR</th>
        <th>PRODUCT QUANTITY</th>
        <th>PRICE</th>
        <th></th>
      </tr>";

  // Get DB results and loop, outputting table rows with counter
  $pplresult = mysql_query("SELECT * FROM repplac") or die(mysql_error());
  for ($i = 0; $row = mysql_fetch_assoc($pplresult); $i++) {
    echo "
      <tr>
        <td>".htmlspecialchars($row['Sname'])."</td>
        <td>".htmlspecialchars($row['Pname'])."</td>
        <td>".htmlspecialchars($row['Psize'])."</td>
        <td>".htmlspecialchars($row['Pcolour'])."</td>
        <td>
          <input type='text' name='item[$i][Pquantity]' id='Pquantity' value='".htmlspecialchars($row['Pquantity'])."' />
          <input type='hidden' name='item[$i][Pidno]' id='Pidno' value='".htmlspecialchars($row['Pidno'])."' />
        </td>
        <td>".htmlspecialchars($row['Price'])."</td>
        <td><a href='deleteproduct.php?del=".htmlspecialchars($row['Pidno'])."'>delete</a></td>
      </tr>";
  }

  // Close table and form
  echo "
    </table>
    <input type='submit' value='Submit' />
    </form>";

?>

 $queryreg = mysql_query("
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       Uname = '{$_SESSION['username']}'
        ")

Check if this returns true or false. If it returns false, you have an error in your SQL connection, query.
If it returns true, the query should be ok.

Also, shouldnt you make a variable with the query which then gets run by mysql_query, and not a variable with mysql_query in it? I don’t remember making queries this way.

it returned true, and also i have assigned a variable but it is not updating


if(array_key_exists('item', $_POST)){
    $items = $_POST['item'];


    //Loop through $_POST items, updating the database for each item
    foreach ($items as $item) {
        $Pquantity = intval($item[0]);
        $Pidno = intval($item[1]);
         $queryreg ="
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       Uname = '{$_SESSION['username']}'
        ";
       mysql_query($queryreg) or die(mysql_error());

    }

Did you check if the value of $Pidno is what you expect it to be?

Also, is the value of $Pquantity correct or is it the old quantity instead of the new one?

when i use

"<pre>";print_r($_POST); echo "</pre>";

it comes out with the new values,(showing that it has been posted
but the code does not update with the post data,
also i use affected _num_rows, it comes back with a result ,
but in real sense it is not updating

$queryreg ="
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       Uname = '{$_SESSION['username']}'
        ";

Echo this just before you send the query, does the query work in phpmyadmin or similar database tool?

edit: code block

the code works in phpmy admin,
that is i substitute the variables say with a number, and the uname, with a proper username

Ow… try change your query like this:

$queryreg ="
            UPDATE repplac
                 SET Pquantity = '" . $Pquantity . "'
                 WHERE
                       Pidno = '" . $Pidno . "'
                 AND
                       Uname = '" . $_SESSION['username'] . "'
        ";

tried it still did not update

When you echo that query and paste it in phpmyadmin?

when i echo it, like substituting it with values, and real user name, it updates the db

You did this?

$queryreg ="
            UPDATE repplac
                 SET Pquantity = '" . $Pquantity . "'
                 WHERE
                       Pidno = '" . $Pidno . "'
                 AND
                       Uname = '" . $_SESSION['username'] . "'
        ";

echo $queryreg; exit;

Can you show us what is echooed?

brense it so funny when i echo it say the original quantity is 5, it comes back with value of 1
also say the original quantity is 5 and i change to 7, when it is echoed it comes back with the value of 1

I see, but the rest of the values are okay?

Can you modify your code like this:

if(array_key_exists('item', $_POST)){
    $items = $_POST['item'];


    //Loop through $_POST items, updating the database for each item
    foreach ($items as $item) {

        echo $item[0] . "\
";

        $Pquantity = intval($item[0]);

        echo $Pquantity;exit;

        $Pidno = intval($item[1]);
         $queryreg ="
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = {$Pidno}
                 AND
                       Uname = '{$_SESSION['username']}'
        ";
       mysql_query($queryreg) or die(mysql_error());

    }

And tell me if the two values are the same or not? It should look like:
1
1

i filled the form initially with two items, one with quantity 4 and the other with quantity 5, and changed it to 8 and 9 resp, and when i submitted it it came back with 0(that is echoed 0)