Hello and thank you in advance for any help that can be provided.
I am fairly new to PDO and am starting my first development project using PDO.
I am tryin to insert three form field values into a database. However one form field is an array.
The insert will work but the page times out before redircting to the next page. I am not sure about this insert statement as I think it is the $i = $i + 1; loop that causes it time out.
What I would like to write is:
For each indicator entered add the user_id and the indicator.
Can anybody tell me where I am going wrong and how I can fix it?
Here is my insert code
$user='root';
$pass='root';
$user_id='3';
$dbh = new PDO('mysql:host=127.0.0.1;dbname=databsename', $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$i = 0;
while($i < count($indicator)){
if(trim($indicator[$i]) != ""){
$stmt = $dbh->prepare("INSERT INTO worksheet SET user_id='$user_id' dateTime='NOW()', indicator='{$indicator[$i]}'");
$stmt->execute();
$i = $i + 1;
HEADER("LOCATION:form-page2.php");
}
}
Thanks