Hello everyone,
i m having problem parsing multi values in database, what i m trying to do is i have a field record page as seen below,
atn.php
<?php
// Connection
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("examination", $con);
$result = mysql_query("SELECT id,Name FROM examination_creg WHERE attendence='1'");
echo "<form method='post' action='send.php'>";
echo "<table border='1'>
<tr><th>Name</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='text' name='name[]' id='name[]' value='".$row['Name']."' />" . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<td>" . "<input type=submit name=send value=Submit />" . "</td>";
echo "</form>";
?>
Above form has 3 repeated records from database table, as seen below
Source view from browser of atn.php
<form method='post' action='send.php'><table border='1'>
<tr><th>Name</th></tr><tr><td>
<input type='text' name='name[]' id='name[]' value='Awais Aslam ' /></td></tr><tr><td>
<input type='text' name='name[]' id='name[]' value='Ali' /></td></tr><tr><td><input type='text' name='name[]' id='name[]' value='Umer' /></td></tr></table><td>
<input type=submit name=send value=Submit /></td></form>
Now once i send record to send.php it send 3 values into as post method into send.php which contain following code
send.php
<?php
// Connection
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("examination", $con);
for($i=1; $i < 3; $i++) {
$name = $_POST['name'][1];
$sql="INSERT INTO examination_attendence (name) VALUES($name)";
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
When i click submit in atn.php page it send 3 input records into send.php, when i go to examination table, there only 1 record add, why not 3 records adding to mysql table ?
id name
1 1
i need it to post all 3 records into database when i click send button, can anyone help please ?
id name
1 1
2 2
3 3