Solved

How to retrieve data related to last id inserted into database

Posted on 2016-11-21
3
66 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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
 
LVL 1

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 110

Expert Comment

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

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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