Solved

How to retrieve data related to last id inserted into database

Posted on 2016-11-21
3
24 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 108

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 108

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now