Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Guys I am having a problem using mysql_insert_id() function

Here is the result if ill execute my first query:

result:
id user Fullname Yrlvl etc
10 1232 Patrick 2015

PHP
$form_data = array('id'=>'','user' => $user, 'pass'=>$pass, 'fname'=>$fname,'mname'=>$mname,'lname'=>$lname,
        'contact'=>$contact, 'email'=>$email, 'yrlvl'=>$yrlvl, 'user_type'=>'student','date_registered'=>'');
$query = dbRowInsert('account', $form_data)

====================================================
Next When I will execute my 2nd query

PHP
mysql_query("insert into student_section (`id`,`sname`,`user`) values (".mysql_insert_id().",'$sname', '$user')");


Here is the result

secid id Sname User
1 10 Sample 1232

But If i will execute my last query

PHP
mysql_query("insert into first (`id`,`subject`,`grade`) 
          	values (".mysql_insert_id().", 'Filipino', '0'),
          	('$userid', 'English', '0'), 
          	('$userid', 'Mathematics','0'), 
          	('$userid', 'Science', '0'),
          	('$userid', 'Araling Panlipunan', '0'),
          	('$userid', 'Technological and Livelihood Education', '0'),
          	('$userid', 'Music, Arts, Physical Education and Health', '0'),
          	('$userid', 'Edukasyon sa Pagpapahalaga', '0'),
          	('$userid', 'Computer Education', '0')
          	") or die(mysql_error());


firstid id subject grade
1 1 english 95

My Problem is after I executed my last query the ID it will get was the secid of the 2nd query not the id.

I hope you can help me
Posted
Updated 11-Feb-15 3:51am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900