I am using form to insert data into SQL.
This is my form:
<form action="insert.php" method="POST">
Name:<input type="text" name="firstname[]" />
</form>
and this is my PHP code:
<?php
$con = mysql_connect("localhost", "root", "root");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
while ($array = $result->fetch_assoc()) {
$query = "INSERT INTO test(firstname) VALUES ('{$array['firstname']}')";
$result = $database->query($query);
}
mysql_close($con);
?>
It shows an error. Any help?
$resultis defined before one enters yourwhileloop...