# php + mysql - Fields

**URL:** <https://www.phphelp.com/t/php-mysql-fields/18909>\
**Category:** General PHP Help\
**Created:** [November 14, 2012, 4:28am UTC](https://www.phphelp.com/t/php-mysql-fields/18909 "2012-11-14T04:28:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![redzwanlatif](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@redzwanlatif](https://www.phphelp.com/u/redzwanlatif)\
**Post date:** [November 14, 2012, 4:28am UTC](https://www.phphelp.com/t/php-mysql-fields/18909/1 "2012-11-14T04:28:49Z")

</div>

[b]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[/b]

[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);

[/php]  
  
form\_post.php :  
   
[php]

Class Name: Student's Name: Student's Name: Student's Name: [/php]

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 🙂

---

<div class="post-metadata">

**Author:** ![wilson382](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wilson382](https://www.phphelp.com/u/wilson382)\
**Post date:** [November 14, 2012, 7:05pm UTC](https://www.phphelp.com/t/php-mysql-fields/18909/2 "2012-11-14T19:05:21Z")

</div>

why is it not working?  
what does it do?
