I'm trying to insert data from an array into my database. I found few people that had similar problems so it could be duplicate, but the answers didn't help me at all, because they didn't have the $i
variable in the code. So could you please help me insert these values to my database?
for ($i=0; $i < $_SESSION["count"]; $i++) {
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = ("INSERT INTO dite (name, lname, adress, bday, inf1, inf2, inf3, id_o, id_m, id_p) VALUES (?,?,?,?,?,?,?,?,?,?);");
$stmt->bind_param("sssssssiii",$_SESSION["name$i"], $_SESSION["lname$i"],
$_SESSION["adress$i"], $_SESSION["bday$i"],
$_SESSION["inf1$i"], $_SESSION["inf1$i"],
$id_o, $id_m, $id_p);
$stmt->execute();
printf("%d Row inserted.
", $stmt->affected_rows);
$stmt->close();
$conn->close();
}
Every help would be greatly appreciated!
EDIT:
If I did echo loop
on every session I would get this:
test_name0
test_lname0
test_address0
test_bday0
test_inf10
test_inf20
//(blank)
test_name1
test_lname1
test_address1
test_bday1
test_inf11
//(blank)
asdfg1
and $id_o = 0; $id_m = 0; $id_p = 0;
And error looks like this:
Call to a member function bind_param() on string in C:\wamp64\www\login\file.php on line 210.
Line 210 is:
$stmt->bind_param("sssssssiii",$_SESSION["name$i"], $_SESSION["lname$i"],