mysql_insert_id() not working
<pre><code>&lt;?php

$userid = $_SESSION['user_id'];
$price = $ad['price'];
$owner = $ad['owner']; //owner of advertisement

//make a bid for this advertisement
$query = "INSERT INTO bids (id, ad, bidder, bid, bidwhen, owner, quantity)
         VALUES (NULL, '$adid', '$userid','$price', now(), '$owner', 1)";
$bidData = mysqli_query($dbc, $query);

$message = $_POST['message']; //message to owner

if ($message != "") { //if message box is not empty insert comment
    $title = $ad['title'];
    $bidid = mysql_insert_id($bidData); //Line 123 get last id of bid insert and put it into message query for reference

    $query = "INSERT INTO messages (sentto, sentfrom, sentat, message, title, bid)
    VALUES ('$owner', '$userid', now(), '$message', '$title', '$bidid')";
    $messageData = mysqli_query($dbc, $query);
}

?&gt;
</code></pre>

<p>Error message:</p>

<pre><code>mysql_insert_id() expects parameter 1 to be resource, boolean given
</code></pre>

<p>When i dont pass a parameter i get this error message:</p>

<pre><code>Warning: mysql_insert_id() [function.mysql-insert-id]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Users\Jonny\Desktop\projects\xampp\htdocs\phpprojects\lets\ad.php on line 123

Warning: mysql_insert_id() [function.mysql-insert-id]: A link to the server could not be established in C:\Users\Jonny\Desktop\projects\xampp\htdocs\phpprojects\lets\ad.php on line 123
</code></pre>

<p><strong>Solution Code:</strong></p>

<pre><code>&lt;?php

$userid = $_SESSION['user_id'];
$price = $ad['price'];
$owner = $ad['owner']; //owner of advertisement

mysqli_close($dbc);
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$dbc) {
    die('Could not connect: ' . mysqli_error());
}
mysqli_select_db($dbc, 'databasename');

//make a bid for this advertisement
$query = "INSERT INTO bids (id, ad, bidder, bid, bidwhen, owner, quantity)
         VALUES (NULL, '$adid', '$userid','$price', now(), '$owner', 1)";
$bidData = mysqli_query($dbc, $query);

$message = $_POST['message']; //message to owner

if ($message != "") { //if message box is not empty insert comment
    $title = $ad['title'];
    $bidid = mysql_insert_id($dbc); //get last id of bid insert and put it into message query for reference

    $query = "INSERT INTO messages (sentto, sentfrom, sentat, message, title, bid)
    VALUES ('$owner', '$userid', now(), '$message', '$title', '$bidid')";
    $messageData = mysqli_query($dbc, $query);
}
?&gt;
</code></pre>
