Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you mean you only get the last filled data from each different fields that happens because your fields name is not a array, change the names adding on end <strong>[]</strong></p> <p>Like that:</p> <pre><code>&lt;input type='text' name='Obstacle[]'&gt; </code></pre> <p>And the same for the others fields. Also you can optimize your php code a little bit more like that bellow. I don't have your code but you can use var_dump($_POST) to check and correct.</p> <p><strong>code updated</strong></p> <pre><code>&lt;?php //simulating data from form $_POST = array( 'Obstacle' =&gt; array('ob1', 'ob2', 'ob3'), 'Likelihood' =&gt; array('l1', 'l2', 'l3'), 'Severity' =&gt; array('s1', 's2', 's3'), 'Priority' =&gt; array('p1', 'p2', 'p3'), ); $user = 1; //the code $sql = "INSERT INTO obstacles (ObstacleDescription, Priority, Uncertainty, Severity, UserName, ComplianceID, Accepted) VALUES (:ID, :obstacleDec, :priorityScale, :likelihoodScale, :severityScale, :aUser, :compID, :accepted)"; // $stmt = $db-&gt;prepare($sql); for ($i=0; $i&lt;count($_POST['Obstacle']); $i++) { $values = array(':obstacleDec'=&gt;$_POST['Obstacle'][$i],':likelihoodScale'=&gt;$_POST['Likelihood'][$i], ':severityScale'=&gt;$_POST['Severity'][$i],':priorityScale'=&gt;$_POST['Priority'][$i], ':aUser'=&gt;$user, ':compID'=&gt;'', ':accepted'=&gt;'' ); // var_dump($values); try{ $result= $stmt-&gt;execute($values); } catch(PDOException $ex){ die("Failed to run query: " . $ex-&gt;getMessage()); } } header("Location: obstacles.php"); die("Redirecting to obstacles.php"); //the ifs you have here are not necessary, your code will never get here </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload