Have you checked that you are getting all student elements from the form before adding to the database? Looks like you are using the same names for each form element, meaning you will only get one student in the create.php script
A:
code-zoop
2010-01-22 10:31:45
+1
A:
if you name change your html to:
<input type="text" name="INAME[]" value="" />
you should be able to to access them as $_POST['INAME'][0] and $_POST['INAME'][1]
you should also be using mysql_real_escape_string() to prevent SQL injection attacks
Twelve47
2010-01-22 10:36:27
A:
To insert multiple values in Mysql you can use the following syntax:
INSERT INTO table_name (colA, colB) VALUES (valA_1, valB_1), (valA_2, valB_2), ... (valA_n, valB_n)
For getting this input data from the form, use Twelve47's hint.
Thus, the code might look something like:
$sql = 'INSERT INTO table_name (colA, colB) VALUES ';
$insert = array();
foreach ($_POST['inputFieldA'] as $key => $value) {
$insert[] = '("' . $_POST['inputFieldA'][$key] . '", "' . $_POST['inputFieldB'][$key] . '")';
}
$sql .= implode(',', $insert);
... [do query and use data here]...
Where inputFieldA and inputFieldB are declared as:
<input type="text" name="inputFieldA[]" value="" />
<input type="text" name="inputFieldB[]" value="" />
Of course, you should sanitize your input, either by escaping using mysql_real_escape_string, or by using the prepared statements feature of either mysqli extension or PDO extension.
Hope that helps.
alexb
2010-01-22 10:51:15