php + mysql - Fields

[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 :slight_smile:

why is it not working?
what does it do?

Sponsor our Newsletter | Privacy Policy | Terms of Service