khan kaka Posted April 21, 2004 Share Posted April 21, 2004 how can i pass the id of inserted data to next page? i want to be able to display the record i have inserted in to a table. i am using php and mysql. Quote Link to comment https://forums.phpfreaks.com/topic/1804-passing-the-id-of-inserted-data-to-next-page/ Share on other sites More sharing options...
Shaun Posted April 23, 2004 Share Posted April 23, 2004 try using variables. like <?php $data = 'Hello World'; echo ($data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/1804-passing-the-id-of-inserted-data-to-next-page/#findComment-5927 Share on other sites More sharing options...
khan kaka Posted May 8, 2004 Author Share Posted May 8, 2004 thanks for your feed back but can you plz explaing a bit more. its driving me crazy. cheers Quote Link to comment https://forums.phpfreaks.com/topic/1804-passing-the-id-of-inserted-data-to-next-page/#findComment-5996 Share on other sites More sharing options...
yesm Posted May 11, 2004 Share Posted May 11, 2004 You can access the id of data inserted to a MySQL table, by storing the value of mysql_insert_id() to a session var. Make sure the table has a AUTO_INCREMENT option assigned to it (in my case 'member_id). This way you can pass the value on to the next page. Here is a sample script: <?php // Start a session and connect to MySQL session_start(); db_connect(); // Make query $query = "INSERT INTO members ( username, password ) "; ."VALUES ( '$u', '" . md5( $p . "' )"; // Run query $result = mysql_query( $query ); if ( $result ) { // If the query was succesful // Store the row id in session var $_SESSION['member_id'] = mysql_insert_id(); $rows_aff = mysql_affected_rows(); echo "$rows_aff row affected."; } else { echo "0 rows affected."; } ?> Script to print the value on the next page: <?php // Start the session to access its values session_start(); // Print value echo $_SESSION['member_id']; ?> I hope this solve your problems Quote Link to comment https://forums.phpfreaks.com/topic/1804-passing-the-id-of-inserted-data-to-next-page/#findComment-6014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.