Hi all...i am working on a project to capture students' data for an educational institution. I want to have a form that allows multiple student records to be filled in at once..e.g(this is the form):
..
for the code to insert it into the database..this is what i came up with:
...problem is its not inserting anything..i need help on getting these values inserted and also the "hashing" of the passwords..plea se help me out.Thanks
Code:
<html>
<body>
<table>
<form method="post" action="array_post.php"
<?php
$i=2;
for($x = 1; $x <=$i; $x++)
{echo '<tr><td>Registration Number:<td><input type=text name="reg_no[]"></td><td>First Name:</td><td><input type=text name="first_name[]"><td>Last Name:</td><td><input type=text name="last_name[]"></tr>';}
?>
<tr><td colspan="7" align="center"><input type="submit" value="Submit Names" />
</td></tr></form>
</table>
</body>
</html>
for the code to insert it into the database..this is what i came up with:
Code:
<?php
include 'poly_connect.php';
foreach ($_POST['reg_no'] as $row=>$reg_no)
$id = mysqli_real_escape_string($link,$reg_no);
$first_name = mysqli_real_escape_string($link,$_POST['first_name'][$row]);
$last_name = mysqli_real_escape_string($link,$_POST['last_name'][$row]);
$password=mysqli_real_escape_string($link,sha1($_POST['password'][$row]));
$sql = "INSERT INTO
students(reg_no,first_name,last_name)
VALUES('" . $reg_no . "','" . $first_name . "',
'" . $last_name . "','" . $password. "'
)";
$result = mysqli_query($link,$sql) or die ("error".mysqli_error($link));
?>
Comment