**Hi. These are my structures :
I got 2 tables in phpMyAdmin :
- Class ( classid(pk), className )
- Students ( studentid(pk), classid(fk), studentName ) 1 form.php and 1 form_post.php
I've done this in 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>
It's a form for registering class and students in it. In phMyAdmin student table, there's a field/column for studentid(pk), a field/column for classid(fk), a field/column for studentName while this code which I got from my friend got 3 students name field. How to insert the 3 students name into the phpMyAdmin student table's studentName column with the same class foreign key? The red colored words are the confusing one. I'm still a beginner and I tried all the night to get this work. But, I'm still stuck. Thank you :)