Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    problem with update with multiple textbox

    hello anyone could help me..

    I have like 4 text field and 1 button..

    example:
    PHP Code:
    echo '<form name="prod" method="post">';
    $query="select * from products";
    $result=mysql_query($query);
    while(
    $row=mysql_fetch_array($result))
    {
    echo 
    '<input type="text" name="quantity" value="$row[quantity]">';
    }
    echo 
    '<input type="submit" name="update" value="Update">';
    </
    form>

    if(isset(
    $_POST['update']))
    {
    foreach(isset(
    $_POST['qnty']))
    {
    mysql_query("update products set quantity='$_POST['qnty'] where ip='$ip'");

    }

    What i want to happen is , I want to update the input of quantity, if the value of the textbox(quantity) is 3 and im going to type 5 then it will update into what is being input in the quantity field. my problem is the last textbox will only be update.. since it has multiple number of textfield and there is only 1 submit button..

    Anyone could help me this..

    Thanks and happy new year...

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    echo '<form name="prod" method="post">';
    $query="select * from products";
    $result=mysql_query($query);
    while(
    $row=mysql_fetch_array($result))
    {
    echo 
    '<input type="text" name="quantity'.$row['ip'].'" value="'.$row[quantity].'">';
    }
    echo 
    '<input type="submit" name="update" value="Update">';
    </
    form>

    if(isset(
    $_POST['update'])) {
      foreach(
    $_POST as $key => $value) {
        
    $ip preg_replace("/quantity(\d+)/","$1",$key);
        if(
    $ip !== $key){
          
    mysql_query('update products set quantity='.$value.' where ip='.$ip);
        }
      }

    is not tested and I presume that field id from products table is integer.

    nest regards


  •  

    Posting Permissions

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