mysql_insert_id() not working

ALStompoRoDog

New Member
\[code\]<?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 = http://stackoverflow.com/questions/3784079/mysqli_query($dbc, $query);$message = $_POST['message']; //message to ownerif ($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 = http://stackoverflow.com/questions/3784079/mysqli_query($dbc, $query);}?>\[/code\]Error message:\[code\]mysql_insert_id() expects parameter 1 to be resource, boolean given\[/code\]When i dont pass a parameter i get this error message:\[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 123Warning: 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\]Solution Code:\[code\]<?php$userid = $_SESSION['user_id'];$price = $ad['price'];$owner = $ad['owner']; //owner of advertisementmysqli_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 = http://stackoverflow.com/questions/3784079/mysqli_query($dbc, $query);$message = $_POST['message']; //message to ownerif ($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 = http://stackoverflow.com/questions/3784079/mysqli_query($dbc, $query);}?>\[/code\]
 
Back
Top