PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I find the ID of a new row added to a table?


If you are adding data to a mySQL table then you will often want to know the ID of a row you have just inserted so that you can reference it elsewhere. Often you'll add to a table with an auto_increment ID field and then want to use this to store other information on other tables.

Here's how you do it:

<?php
$q 
mysql_query("INSERT INTO mytable VALUES('test')");
$rownumber mysql_insert_id();
//$rownumber contains the id of the new row
?>



ASK A QUESTION

More mysql PHP Questions

What is difference between mysql_fetch_array and mysql_fetch_object?

I tried to do query,but it didnt work i receive an error message arning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in

How do i list a record in front that is recently added to the table?

HOW can i retrieve database elements and make them select options on a form My Test Form Please, choose item to order:

How do I order the results of my query?



Custom Search