我正在制作一个将学生信息放入学生表的表格。部分此信息需要外键作为parent表中的parent_guardian_id。我想提供父母的帮助。从选择或下拉列表中选择名称以输入外键。好像我需要同时进行GET和POST?我需要至少与其他2个页面一起完成此操作。感谢您的任何见解。
//Check for student first name:
if (empty($_POST['student_first_name'])) {
$errors[] = "Please enter the student\'s first name.";
} else {
$student_first_name = mysqli_real_escape_string($dbc,($_POST['student_first_name']));
}
if (empty($errors)){//If requirements met:
$query="INSERT INTO student (student_first_name, student_last_name,
student_street, student_city, student_zip, student_phone,
student_email, parent_guardian_id)
Values ('$student_first_name', '$student_last_name',
'$student_street', '$student_city', '$student_zip', '$student_phone',
'$student_email', '$parent_guardian_id')";
$result=mysqli_query($dbc,$query);
if ($result){
echo "<center><p><b>A new STUDENT has been added.</b></p><br/>";
echo "<center><a href=studentadd.php>Show All STUDENTS</a> </center>";
exit();
} else {
$errors[] = "<p>The record could not be added due to a system error. </p>";
$errors[] = mysqli_error($dbc) . "</p>";
}
}
}
mysqli_close($dbc);}
?>
<form action="studentadd.php" method="post">
<p>First Name: <input type="text" name="student_first_name" size="50" value=
"<?php echo $_POST['student_first_name']; ?>"/><p><br />
<p>Last Name: <input type="text" name="student_last_name" size="50" value=
"<?php echo $_POST['student_last_name']; ?>" /><p><br />
<p>Street Address: <input type="text" name="student_street" size="50" value=
"<?php echo $_POST['student_street']; ?>" /><p><br />
<p>City: <input type="text" name="student_city" size="50" value=
"<?php echo $_POST['student_city']; ?>"/><p><br />
<p>State: <input type="text" name="student_state" size="50" value=
"<?php echo $_POST['student_state']; ?>"/><p><br />
<p>Zip: <input type="text" name="student_zip" size="50" value=
"<?php echo $_POST['student_zip']; ?>"/><p><br />
<p>Phone: <input type="text" name="student_phone" size="50" value=
"<?php echo $_POST['student_phone']; ?>"/><p><br />
<p>Email Address: <input type="text" name="student_email" size="50" value=
"<?php echo $_POST['student_email']; ?>"/><p><br /></form>
<p>Parent/Guardian: <select name="parent_guardian"
id="parent_guardian" size="20"
value="<?php echo $row['mother_guardian_first_name'] . "
, " . $row['mother_guardian_last_name'] . "
, " . $row['father_guardinan_first_name'] . "
, " . $row['father_guardian_last_name'];
$_POST['parent_guardian_id']; ?>"/>Name Goes Here</select><p><br />
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />
<input type="hidden" name="submitted" value="true" /></p>
</form>
<?php
//include the footer
include ("footer.php");
?>