Solved

How to retrieve data related to last id inserted into database

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wamp versus xampp 4 44
join tables 4 50
How to use md5 hashing 3 27
PHPStorm debugging issues 1 23
This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

22 Experts available now in Live!

Get 1:1 Help Now