Php 我如何从发布信息,并将同样需要发布到同一数据库的信息从中获取到表单中?

Php 我如何从发布信息,并将同样需要发布到同一数据库的信息从中获取到表单中?,php,html,mysql,forms,Php,Html,Mysql,Forms,我正在制作一个表格,将学生信息放入学生表中。此信息的一部分需要外键作为parents表中的parents\u guardian\u id。我想从选择或下拉列表中选择父母的名字来输入外键。好像我需要同时获得和发布?我需要这样做,至少有两个其他页面。谢谢你的洞察力 //Check for student first name: if (empty($_POST['student_first_name'])) { $errors[] = "Please enter the student\'s

我正在制作一个表格,将学生信息放入学生表中。此信息的一部分需要外键作为parents表中的parents\u guardian\u id。我想从选择或下拉列表中选择父母的名字来输入外键。好像我需要同时获得和发布?我需要这样做,至少有两个其他页面。谢谢你的洞察力

//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");

?>

HTML没有值属性。您需要标记,并且需要循环选择查询结果。顺便说一下,我看不出你从数据库中选择父母的位置。哦,家长选择的是表单之外的内容。嗯。旁注:使用事先准备好的语句。你对这样的注入非常开放。在这段代码之前,我有很多转义字符串。我在上面放了一个。值是$row段,这显然是不正确的。那么父母的选择就放在表格里面了?这就是我所困惑的。谢谢你的提示。如果有人能提供一些关于如何实现这一点的说明,我将非常感激。干杯。请阅读这篇关于如何防止SQL注入的文章。