After submitting a form and inserting the data into a table, I want to search this table and set a session variable to use on another database insert. Below is the PHP which inserts and then searches the newly updated table.
require_once("db_connect.php");
if($db_server) {
mysql_select_db($db_database) or die ("<p>Couldn't find database.</p>");
$query = "INSERT INTO routes (user_id, title, description, startlat, startlng, endlat, endlng) VALUES ('$user_id', '$title', '$desc', '$startlat.', '$startlng', '$endlat', '$endlng')";
if (mysql_query($query)) {
$get_id = mysql_query("SELECT * FROM routes WHERE user_id, title = '$user_id', '$title'");
$route_id = mysql_result($get_id, 0,'id');
$_SESSION['route_id'] = $route_id;
echo $route_id;
} else {
$message = ("Insert failed. " . mysql_error() . "<br/>" . $query);
}
} else {
$message = "Error: could not connect to the database.";
}
mysql_close($db_server);
I get this warning:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in...
which refers to this line of the above code:
$route_id = mysql_result($get_id, 0,'id');
Basically what I am attempting to do is get the 'id' of the newly inserted row (the id is the primary key and is auto incremented) and set it as the $route_id so that on my next page I can insert this value into another table as a route_id which is used to link the two tables together.