1

Hi I'm receiving this warning when trying to retrieve the insert id

Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource

in

mysql_query($importword); 
$word_id = mysql_insert_id($importword);
codaddict
  • 445,704
  • 82
  • 492
  • 529
acctman
  • 4,229
  • 30
  • 98
  • 142

4 Answers4

3

$importword is the query that you are executing using msql_query.

Next you are passing the query to mysql_insert_id which is incorrect. mysql_insert_id takes the link identifier which is optional.

If you are not having multiple connections open, just don't pass anything:

mysql_query($importword); 
// do some error checking.

$word_id = mysql_insert_id();

so that it uses the last link opened by mysql_connect

codaddict
  • 445,704
  • 82
  • 492
  • 529
3

if you get the id and that id you want to insert just write mysql_insert_id(); after your query.

imad
  • 74
  • 1
  • 6
1

You're supposed to pass the connection, or leave it empty to use the last one opened.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

mysql_insert_id take the resource identifier not the query

either pass resource or leave blank

$word_id = mysql_insert_id();
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153