Php mysql select and insert problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
surya.n.j
Forum Newbie
Posts: 2
Joined: Thu Jun 18, 2009 7:05 am

Php mysql select and insert problem

Post by surya.n.j »

Hi every one i have a registration application, where the user details are maintained in two tables, iam generating a auto increment value for userid and inserting it in the table when i click on subimt. Now i want to select the user id after the insert statement is executed to place some fields in another table at the submission time. I cannot get the id value even i wrote next to insert statement and i even tried by closing mysql connection after insert and again connecting for select it does notwork if anyone has solution please give me solution
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Re: Php mysql select and insert problem

Post by icesolid »

Code: Select all

<?php
$result = mysql_query("SELECT `userid` FROM `table_name` ORDER BY `userid` DESC");
$row = mysql_fetch_array($result);
 
// Print the newest userid in the database
 
echo $row['userid'];
?>
Post Reply