Reputation: 607
I actually read an answer here, the user says this happens when your table is not having any autoincrement
column but am already having that, the other is connection is not established, but when I used this
if(!$running_db) {
echo 'False';
} else {
echo 'true'; //Returns me true so connection is establised
}
Than why it is returning me 0
? Actually am inserting on page.php
and after successfully inserted user is redirected to result.php
page where I am echoing out the id using mysqli_insert_id
so that I can highlight the field but it returns me 0 and the table row is thus failing to highlight
P.S Am using procedural way
Upvotes: 0
Views: 1504
Reputation: 2061
Note from the php manual :
http://php.net/manual/en/function.mysql-insert-id.php
"Because mysql_insert_id() acts on the last performed query, be sure to call mysql_insert_id() immediately after the query that generates the value. "
Retrieve the value on the same page, place it in session and then access the value from the session variable on any other page.
Upvotes: 2
Reputation: 2013
When you redirect to the new script you loose that information. Without seeing your code, all I can advice is to reat the mysqli_insert_id
in the page.php
script, save it in a SESSION variable and then redirect to result.php
where you check that SESSION variable and find the saved id in it.
Upvotes: 2