【发布时间】:2012-11-02 15:39:22
【问题描述】:
**嗨。这些是我的结构:
我在 phpMyAdmin 中有 2 个表:
- 类(classid(pk), className)
- 学生(studentid(pk)、classid(fk)、studentName) 1 个 form.php 和 1 个 form_post.php
我已经在 form.php** 中完成了这个
include_once("connection.php");
$className= $_POST["className"];
$studentName1= $_POST["studentName1"];
$studentName2= $_POST["studentName2"];
$studentName3= $_POST["studentName30"];
$sql = "insert into class(className) values ('$className')";
mysql_query($sql);
$lastid=mysql_insert_id();
$sql2= "INSERT INTO students (studentid, classid, studentName)
VALUES (' ', $lastid, '$studentName')";
mysql_query($sql2);
form_post.php:
<tr>
<td width="140"><span class="order">Class Name: </span></td>
<td><span class="order">
<input name="className" type="text" id="className" size="35" />
</span></td>
</tr>
<tr>
<td width="132"><span class="order">Student's Name: </span></td>
<td><span class="order">
<input type="text" name="studentName1" id="studentName1" />
</span></td>
</tr>
<tr>
<td width="132"><span class="order">Student's Name: </span></td>
<td><span class="order">
<input type="text" name="studentName2" id="studentName2" />
</span></td>
</tr>
<tr>
<td width="132"><span class="order">Student's Name: </span></td>
<td><span class="order">
<input type="text" name="studentName3" id="studentName3" />
</span></td>
</tr>
这是一种用于在其中注册班级和学生的表格。 在 phMyAdmin 学生表中,studentid(pk) 有一个字段/列,classid(fk) 有一个字段/列,studentName 有一个字段/列,而我从朋友那里得到的这段代码有 3 个学生姓名字段。如何使用相同的班级外键将 3 个学生姓名插入 phpMyAdmin 学生表的 studentName 列? 红色的词是令人困惑的词。 我仍然是初学者,我整晚都在努力完成这项工作。但是,我仍然卡住了。 谢谢你:)
【问题讨论】:
标签: php mysql insert phpmyadmin