SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with confusing syntax

    I have list of say 10 products on a page with a form field (used as quantity) as follows.

    <input id="quantity" name="product[<?=$row1['sku'];?>]" type="text" size="2" maxlength="2" />

    The user can enter the desired quantity of those products they are interested in, then the form post back to the same page. I want to populate the form field value="" with the value entered by the user. Usually done like this <?php echo $_POST['name'] ?>

    But in this case the files names are like product[BGS-113468-001]

    I have tried getting the values from the array as follows, but I can't seem to get it syntax right

    Code:
    <input id="quantity" name="product[<?=$row1['sku'];?>]" 
       type="text" size="2" maxlength="2" 
    
    <?php 
    	if(isset($_POST['updateform'])){ 
    	   //$val = $_POST['product']['.$row1['sku'].'];
    	    $val = "$_POST['product']['".$row1['sku']."']";
    	      echo "value='".$val."'";
    	   }
    ?>   
    
    />
    I need help with the $val = line

    I try in 2 ways and get these errors
    I get these respective errors

    Parse error: syntax error, unexpected T_STRING, expecting ']' in ...

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING ...

    Thanks

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    //print_r($_POST['product']);

    foreach ($_POST['product'] as $key => $value) {
        echo 
    "$key:$value\n";


  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this
    Code:
    <input id="quantity" name="product[<?=$row1['sku'];?>]" 
       type="text" size="2" maxlength="2" 
    
    <?php 
        $sku = $row1['sku'];
        if(isset($_POST['product'][$sku])) { 
              echo "value='{$_POST['product'][$sku]}'";
           }
    ?>
    
    />
    The variable $sku isn't totally necessary, but it makes the code easier to read.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a million, that works perfect!!!!

    Quote Originally Posted by cranial-bore View Post
    Try this
    Code:
    <input id="quantity" name="product[<?=$row1['sku'];?>]" 
       type="text" size="2" maxlength="2" 
    
    <?php 
        $sku = $row1['sku'];
        if(isset($_POST['product'][$sku])) { 
              echo "value='{$_POST['product'][$sku]}'";
           }
    ?>
    
    />
    The variable $sku isn't totally necessary, but it makes the code easier to read.

  5. #5
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    $val = $_POST['product']."['".$row1['sku']."']";
    Avi Ben Sheetrit
    Internet Marketing Specialist
    http://www.giftbasketfair.com


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
  •