Reputation: 43
I'm attempting to pull a auto incremented id from a previous query. I receive exception: 1305 FUNCTION THE_NAME_OF_MY_DATABASE.mysqli_insert_id does not exist.
Where can I alter mysql to have this function or what needs to be rephrased? I've googled this and found mixed responses.
$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "create"){
//write the query for character creation
$query = "(all of my stuff that I'm putting into another database that works)";
$query1 = "INSERT INTO playerskill
(skillid, charid)
VALUES ('".$_POST['skills']."',mysqli_insert_id());
";
//what happens when successful or not
if( $mysqli->query($query) ) {
echo $query ;
echo "Character was approved.";
}else{
echo "Database Error: Unable to update record.";
echo $mysqli->errno;
echo mysqli_error($mysqli);
}
}
//what happens when successful or not
if( $mysqli->query($query1) ) {
echo $query1 ;
echo "Character was approved.";
}else{
echo "Database Error: Unable to update record.";
echo $mysqli->errno;
echo mysqli_error($mysqli);
}
Upvotes: 0
Views: 518
Reputation: 168695
Per your code:
$query1 = "INSERT INTO playerskill (skillid, charid)
VALUES ('".$_POST['skills']."',mysqli_insert_id());";
Note that mysqli_insert_id()
, in common with all the other mysqli
functions requires you to specify the DB connection variable.
I note that most of the rest of your code uses the OO syntax for mysqli, which means that the connection variable is specified as the object name. In the case of mysqli_insert_id()
here, you are calling it using the procedural syntax, in which case you must specify the connection var as the first parameter.
So you need either mysqli_insert_id($mysql)
or $mysql->insert_id
That should solve the problem.
Upvotes: 2
Reputation: 6947
Well, you're trying to use a PhP function into a SQL query... it can't work !
Here's a bit of explanation on how to use the function in PhP : http://www.w3schools.com/php/func_mysqli_insert_id.asp
Upvotes: 1