SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    echoing form array

    please i am trying to update a form , but it only updates the last row , i have tried to echo the post values sent(item[Pidno] and item[Pquantity] ) as array but it comes back with just the last row item[Pquantity] update , and it does not return the item[Pidno], where am i going wrong

    PHP Code:
        <?
        $pplresult 
    mysql_query("SELECT * FROM repplac");
        echo 
    "<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>"
    ;
        while(
    $row mysql_fetch_assoc($pplresult)){?>
        <form action='updatepplac.php' method='Post' class='slistbar'>
        <?echo "<tr><td>" .$row['Sname'] ."</td><td>" .$row['Pname'] ."</td><td>" .$row['Psize'] ."</td><td>" .$row['Pcolour'] ."</td><td>" ."<input type='text' name='item[Pquantity]' id='Pquantity' value='{$row['Pquantity']}' >" ."</td><td>" .$row['Price'] ."</td><td>" ?>
        <a href="deleteproduct.php?del=<?php echo $row['Pidno'];?>">delete</a></td></tr>
        <input type='hidden' name='item[Pidno]' id='Pidno' value='<?php echo $row['Pidno']; ?>' ><?php }
        
    // table closing tag
        
    ?>
    the update script
    PHP Code:
        $submit $_POST['submit'];
                
    //$rowdelete = $_GET['del'];
                
    $nPquantity $_POST['item'];
                foreach(
    $nPquantity as $Pquantitys){
        list(
    $pidno$Pquantity) = $Pquantitys;
                echo 
    "$Pquantitys";
                
    //echo "$rowdelete";
                 //echo "$pidno";
                  //echo "$Pquantity";
                
    die(); 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Simplify your form and iron out what is going wrong. It is sometimes even worth coding your form elements in HTML first with hardcoded values, just to check that you have got your understanding right.

    Then just var_dump($_POST) and look into your variables.

  3. #3
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty new to php coding and sql coding but shouldn't $pidno equal something from your database?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •