I don't know why but I'm suddenly getting killed with undefined variable errors. I'm using php5 and yes, I know that mysqli is better table manners but mysql is still supposed to work. Can you see any reason why I would be getting an undefined variable for mysql_insert_id in the below? The information is being put into the database, and the first field is "bid int(11) auto increment primary key" and it's being set.
I'd rather use a mysql_insert_id to get the newly created book id (bid) so that I can make a link to a page (book.php?bid=$bid) where the user can enter information about this book using the book id (bid), rather than perform a query to get it.
require_once('dbconnect.php');
$category_id = "1";
$title = "The Joys of Code Writing";
$query = "INSERT INTO books (category_id, title)
VALUES ('$category_id', '$title')";
$result = mysql_query ($query) or die(mysql_error());
if (mysql_affected_rows() == 1)
{
$bid = @$mysql_insert_id();
echo "<p><a href='book.php?bid=$bid'>Enter Book Info</a></p>";
}
else
{
echo"<p>Could not enter information.</p>";
}