Skip to content Skip to sidebar Skip to footer

Php Code Isn't Allowing Multiple Input Values To Send Through My Form

I am running into a wall with an application I have built. I am brand new to PHP (less than 1 month) and I have written a very complex form with the help of a mentor. Due to a co

Solution 1:

You're trying to name your vars with $. I suppose you want to output php values there, so change your string to look like this:

<td><inputtype="text"name="<?=$product['Val1'] ?>"/></td>

Solution 2:

"$" represents PHP variable and hence it needs to be inside the php tag. Also remember to enclose the echo value with quotes(").

<?phpforeach($results['tags'] as$part) {
        if ($part['category'] == "Part") {
?><tr><td><?=$part['Part']; ?></td><tdclass="text-center"><?=$product['Amount']; ?></td><td><inputtype="text"name="<?=$product['Val1']; ?>" /></td><td><inputtype="text"name="<?=$product['Val2']; ?>" /></td></tr><?php
        }
    }
?>

Solution 3:

The answer was I needed to iterate them since they aren't arrays and append them to the string.

This was accomplished thanks to @SonnY

<scripttype="text/javascript">functionsendData() {
  var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
      data = [],
      name, val1, val2;

  for (var i = 0; i < inputs.length; i++) {
    if ( inputs[i].type === 'submit') {
      continue;
    }

    if ( inputs[i].value ) {
      name = inputs[i].name.split('-val');
      val1 = inputs[i].name.split('val1');

      if (val1.length > 1) {
        data.push({name: name[0], val1: inputs[i].value});
      }
      else {
        data.push({name: name[0], val2: inputs[i].value});
      }
    }
  }

  window.setTimeout(function() {
    sendData();
  },30000);
}

sendData();

Solution 4:

Merry Christmas

Since, Not Much Data Provided. I am assuming from my side. Hope it helps.

Place the value in value attribute. Give name as array type. Like Slot1[], Slot2[] .. Since, There may be more than 1 value for Val1, so name is of array type.

<formaction='SubmitSomePage.php'method='POST'><?php                        
    {
        foreach($results['tags'] as$part)
        {
            if ($part['category'] == "Part")
            {?><tr><td><?=$part['Part']; ?></td><tdclass="text-center"><?=$product['Amount']; ?></td><td><inputtype="text"value="<?=$product['Val1'];?>"name='Slot1[]'/></td><td><inputtype="text"value="<?=$product['Val2'];?>"name='Slot2[]' /></td></tr><?php
            }
        }
    }
    ?>
    .
    .
    <inputtype='submit'value='Submit Details'></form>

SubmitSomePage.php

<?$slot1 = $_POST['Slot1'];
$slot2 = $_POST['Slot2'];

$TotalSlot1 = sizeof($slot1);

for($i = 0; $i<$TotalSlot1;$i++)
{
    $slot1Value = $slot1[$i];       
    $slot2Value = $slot2[$i];

    $Query = "INSERT INTO TableName Set Val1='$slot1Value', Val2='$slot2Value'";
    //Execute Query Here.   
}
?>

Post a Comment for "Php Code Isn't Allowing Multiple Input Values To Send Through My Form"