• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79
  • Last Modified:

How to retrieve data related to last id inserted into database

I had this question after viewing fade new row in after record insert with jQuery/ajax/php.


So, this loads the last record inserted ID into the table of records and fades in as I wanted per the above question.

$stmt = $link->prepare("INSERT INTO `voucher_categories`(`category_name`) VALUES (?)");
$stmt->bind_param("s", $_POST['cat_name']);
$stmt->execute();
echo $myoutput  = $stmt->insert_id;
$stmt->close();

Open in new window

     

The problem is, I don't actually want the ID number to display, but rather the category name for that particular ID. Do I need to run another SELECT prepared statement or is there a way to do that in the existing (above) prepared statement?
0
Black Sulfur
Asked:
Black Sulfur
  • 2
1 Solution
 
Ray PaseurCommented:
The information you want is already present in $_POST['cat_name'], so you can just do something like this:
echo htmlentities($_POST['cat_name']);

Open in new window

0
 
Black SulfurAuthor Commented:
Haha, I can't believe it is that simple. I am always looking at trying to complicate things when it can be something so simple. Thank you!
0
 
Ray PaseurCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now