SitePoint Sponsor

User Tag List

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

    getting values from array

    please i submitted a form and was trying to use the values.
    when i use
    PHP Code:
    print_r($_POST); 
    it comes back with theses values
    Array ( [item] => Array ( [0] => Array ( [Pquantity] => 1 [Pidno] => 1 ) ) )

    then assigned to $items

    PHP Code:
    if(array_key_exists('item'$_POST)){
        
    $items $_POST['item']; 
    ow can i verify the values
    i tried this
    PHP Code:
      echo $items['item'][Pquantity]; 
    it comes back with nothing

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    foreach($_POST['item'] as $item){
        echo $item['Pquantity'];
    }
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @AnthonySterling that works, please when i try to update, it dosent, can you help look at this code
    (the value in the POST array, is the updated values on the form)
    Array ( [item] => Array ( [0] => Array ( [Pquantity] => 5 [Pidno] => 2 ) [1] => Array ( [Pquantity] => 6 [Pidno] => 1 ) ) )

    PHP Code:
    //print_r($_POST);
    if(array_key_exists('item'$_POST)){
        
    //$items = $_POST['item'];
      //foreach($_POST['item'] as $item){
        //echo $item['Pquantity'] . ", ";
        //echo $item['Pidno'] . ", ";
        //}
        //Loop through $_POST items, updating the database for each item
        
    foreach ($_POST['item'] as $item) { 
            
    $Pquantity intval($item[0]);
            
    $Pidno intval($item[1]); 
            
    $queryreg mysql_query("
                UPDATE repplac
                     SET Pquantity = 
    {$Pquantity}
                     WHERE
                           Pidno = 
    {$Pidno}
                     AND
                           username = '
    {$_SESSION['username']}'
            " 

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You're using numeric indicies for the $item array, you should be using Pquantity, Pidno etc; the numeric ones do not exist.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    its updating now, i used
    PHP Code:
    //print_r($_POST);
    if(array_key_exists('item'$_POST)){
       
    // $items = $_POST['item'];
      //foreach($_POST['item'] as $item){
        //echo $item['Pquantity'] . ", ";
        //echo $item['Pidno'] . ", ";
       // }
        //Loop through $_POST items, updating the database for each item
        
    foreach ($_POST['item'] as $item) { 
            
    $Pquantity intval($item['Pquantity']);
            
    $Pidno = ($item['Pidno']); 
            
    //echo $Pquantity . ", ";
               //echo $Pidno . ", ";
            
    $queryreg mysql_query("
                UPDATE repplac
                     SET Pquantity = 
    {$Pquantity}
                     WHERE
                           Pidno = 
    {$Pidno}
                     AND
                           Uname = '
    {$_SESSION['username']}'
            "
    ) or die(mysql_error()); 


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
  •