Solved

How to retrieve data related to last id inserted into database

Posted on 2016-11-21
3
55 Views
Last Modified: 2016-11-21
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
Comment
Question by:Black Sulfur
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41896252
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
 

Author Comment

by:Black Sulfur
ID: 41896256
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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41896272
Glad to help :-)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question