Halftone
Halftone

Reputation: 21

mysql_fetch_assoc returning NULL

I have an issue with the following script which is suppose the next increment value


$lastidquery = "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE( ) AND TABLE_NAME = 'user';";

$lastid = mysql_query($lastidquery);

$id = mysql_fetch_assoc($lastid);

$next_increment = $id['Auto_increment'];

The mysql_fetch_assoc returns a null while the mysql_query returns = resource(9, mysql result)

Upvotes: 1

Views: 519

Answers (1)

Halftone
Halftone

Reputation: 21

I found the solution thanks to PaulJ.

I was trying to get the next increment value that I need to use as a foreign key in another table when adding a new row.

I actually inserted the data for the parent table, got the last inserted key using $last_id = $connect->insert_id; and then inserted the data in the child table using the obtained id as foreign key.

Upvotes: 1

Related Questions