Neil_Bradley
asked on
fetch row information
I have a simple upload script. The primary key "id_ref" has an "auto increment" property.
What I would like to do is insert the new row then immediately retrieve the id_ref from that new row so it can be echoed on the page.. IE Your information has been uploaded. Your reference number is "echo the id_ref".
Help appreciated.
N
What I would like to do is insert the new row then immediately retrieve the id_ref from that new row so it can be echoed on the page.. IE Your information has been uploaded. Your reference number is "echo the id_ref".
Help appreciated.
N
<?php
function db_connect() {
$result = new mysqli('localhost', 'demo', 'password', 'demo');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
?>
<?php
$conn = db_connect();
$result = $conn->query("insert into myTable values
('', '".$date."','".$_SESSION['trading']."','".$_SESSION['title']."')");
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, that has got it!
Nice tidy solution..
Cheers,
Neil
Nice tidy solution..
Cheers,
Neil
Glad to help you. Good luck with your project.
<?php
$result = $conn->query("selec id_ref from myTable where id_ref = $conn->insert_id");
?>