Link to home
Start Free TrialLog in
Avatar of DReade83
DReade83Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Posting dynamic textboxes using PHP

Please see my code snippet below.

Basically I want to post a number of dymanic textboxes into a DB via PHP. I have done this with checkboxes but can't seem to do this for textboxes too.

Any help would be greatly appreciated. Thanks in advance.
<?php
if(isset($_POST['SubmitForm'])) {
    
    if(isset($_POST['Desc'])) {
        
        foreach($_POST['Desc'] as $str) {
            
            # Connect to DB (via class)
            $this->ConnectDB();
            
            $sql    =    sprintf('UPDATE Products SET
                                 Description = "%s"
                                 WHERE ItemId = %d
                                 AND ProductId = %d',
                                 mysql_real_escape_string($str),
                                 $itemId,
                                 1337);
            
            $query  =    mysql_query($sql);
        }
    }
}
?>
<form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
  <input name="Desc[]" type="text" value="Description 1"> <!-- Item ID: 1 -->
  <input name="Desc[]" type="text" value="Description 2"> <!-- Item ID: 2 -->
  <input name="Desc[]" type="text" value="Description 3"> <!-- Item ID: 3 -->
  <input name="Desc[]" type="text" value="Description 4"> <!-- Item ID: 4 -->
  <input name="Desc[]" type="text" value="Description 5"> <!-- Item ID: 5 -->
  <input name="SubmitForm" type="submit" value="Submit">
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DReade83

ASKER

That worked a treat! Thank you!