I have this arrays of firstname and lastname, i want to insert the names into the database, the arrays looks like this:
Array(
[0] => firstname1
[1] => firstname2
[2] => firstname3
)
Array(
[0] => lastname1
[1] => lastname2
[2] => lastname3
)
I have this code to insert them but it does'nt work
$fname = $_POST['fname'];
$lname = $_POST['lname'];
for($i=0, $count = count($fname); $i < $count; $i++){
$lastname = $lname[$i];
$firstname = $fname[$i];
$query = mysqli_query($con,"INSERT INTO
persons(firstname,lastname)VALUES('$firstname','$lastname')");
}
Printing the strings in the array is not a prolem, but when i insert it an error saying Notice: Array to string conversion in D:\xampp\htdocs\SPAC_Online_Grading_System\system\pages\addfunction.php on line 259 How can i make it work?