I want to retreive the ID from a newly created row in the database.
$new_article_query = "INSERT INTO articles (title, author, keywords, abstract, date, library) VALUES
('".$title."', '".$user_details['username']."', '".$keywords."', '".$abstract."', CURDATE(), '2')";
$new_article_result = mysql_query($new_article_query);
if (!$new_article_result)
{echo "QUERY: ".$new_article_query."<br/>ERROR: ".mysql_error();}
else
{
$new_article = mysql_fetch_array($new_article_result);
$new_id = $new_article['article_id'];
}
The new row is created ok, but I cant get hold of the ID 🙁 .
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in D:\temp\LeaningPHP\transport-planning\posting.php on line 47
I know I could probably find it out by running a "SELECT MAX(article_id) FROM articles" query, but from reading the PHP manual this should be working. Can anyone offer any help? Im sure Im just missing something stupid 😕