Hi guys.
I have a problem with an insert query that is driving me nuts! I have loads of queries running throughout my site, but because this one involves an auto increment in the table, it`s causing problem. I have scanned the other posts on this site, and though I have tried those fixes, it still wont work.
My table is:
CREATE TABLE clubstaff
(
idref
TINYINT AUTO_INCREMENT ,
name
MEDIUMTEXT,
tel
TINYINT,
email
TINYTEXT,
PRIMARY KEY ( idref
)
);
The code I am using (within a function) is:
$result = mysql_query( "INSERT INTO clubstaff (idref, name, tel, email) VALUES (0, '$name', '$tel', '$email'");
(and yes, I have passed all the variables to the function – I have even tried hard coding some test data in)
I then call:
printf("<br>Last inserted record has id %d\n", mysql_insert_id());
as suggested in some of the other posts, but I always get:
Last inserted record has id 0.
Using PHPmyADMIN, when I insert (successfully) the code it generates is:
$sql = 'INSERT INTO clubstaff
( idref
, name
, tel
, email
) ';
$sql .= 'VALUES ( \'0\', \'r\', \'r\', \'r\' );';
$sql .= '';
But I have tried that, and even that doesn`t work.
Oh – I have also tried ‘’ instead of 0 for the idref – same problem, $result returns a fail from the function.
Any ideas anyone?
Thanks in advance…