Hey!
I'm writing a mysql query using sprintf() and assigning it to a variable called $sql before running the query with mysql_query($sql).
However, I want to use mysql_insert_id().. and when I put this in my sprintf() when creating the query, it's obviously always going to be 0.
How can I get around this? (without having to use my custom dbFieldMax() function to return the highest ID number manually..)
Any help will be greatly appreciated!
This is my code if you don't understand what I mean..
$sql = sprintf("INSERT INTO %s " .
" (id, cat_id, name, description, prune_next, locked, display_order, hidden, allow_html)" .
" VALUES (%s, %s, '%s', '%s', %s, %s, %s, %s, %s)",
DB_BB_FORUMS,
mysql_insert_id(),
$_POST['in_category'],
$_POST['forum_name'],
( strlen($_POST['forum_description']) > 0 ? $_POST['forum_description'] : null ),
intval($_POST['forum_prune']),
$_POST['forum_locked'],
(dbFieldMax('display_order', DB_BB_FORUMS) + 1),
$_POST['forum_hidden'],
$_POST['forum_html']
);
if( mysql_query($sql) ) {
redirect("Forum added.", "index.php", 0);
}