简体   繁体   中英

How do I fill primary key value via a form and php query?

I have two tables: student table with the following fields:

  1. student_id (primary key)
  2. firstname
  3. lastname
  4. email

And score table:

  1. student_id (foreign key)
  2. math
  3. biology
  4. physics

I want to insert into score table with a form with php.

I have retrieved form data and stored them in variables:

$math = $_POST ['math'];
$ biology = $_POST ['biology'];  
$ physics = $_POST ['physics'];

Now how do I write the query to insert these data into database? I mean how d I fill value for field student_id which is a primary key.

What should I write instead of aaaa in the following query.

INSERT INTO score VALUES ('aaaa', '$  math', '$ biology', '$ physics');

You can store the student_id in a hidden field in your HTML and access it in your $_POST .

Just give the hidden field a name like name="hiddenStudentId" and it will appear under $_POST["hiddenStudentId"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM