note 84376 modified in function.mysql-insert-id by felipe

From: Date: Fri, 11 Jul 2008 11:37:44 +0000
Subject: note 84376 modified in function.mysql-insert-id by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141399@lists.php.net to get a copy of this message
I solved the problem by inserting a "unique" code, like md5 or session_id. First you insert the date in de database and in the next step you look for de used id. Just a part of the php script. <?php $code = md5(uniqid()); // a random 32 digits code is generated $name = $POST_[name]; $email = $POST_[email]; // first step $mysql_id = mysql_connect("$dbhost","$dbuser","$dbpass"); $sql = "INSERT into database (code,name,email) VALUES('$code','$name','$email')"; $res = mysql_db_query("$db","$sql",$mysql_id); include("error.php"); //second step $mysql_id = mysql_connect("$dbhost","$dbuser","$dbpass"); $sql = "select * from database where code='$code' "; // select the record with the above generated md5 code $res = mysql_db_query("$db","$sql",$mysql_id); include("error.php"); $row = mysql_fetch_row($res); $id = $row[0]; // this is de used id genereted by auto_increment for this input ?> --was-- I solved the problem by inserting a "unique" code, like md5 or session_id. First you insert the date in de database and in the next step you look for de used id. Just a part of the php script. <?php $code = md5(uniqid()); // a random 32 digits code is generated $name = $POST_[name]; $email = $POST_[email]; // first step $mysql_id = mysql_connect("$dbhost","$dbuser","$dbpass"); $sql = "INSERT into database (code,name,email) VALUES('$code','$name','$email'); $res = mysql_db_query("$db","$sql",$mysql_id); include("error.php"); //second step $mysql_id = mysql_connect("$dbhost","$dbuser","$dbpass"); $sql = "select * from database where code='$code' "; // select the record with the above generated md5 code $res = mysql_db_query("$db","$sql",$mysql_id); include("error.php"); $row = mysql_fetch_row($res); $id = $row[0]; // this is de used id genereted by auto_increment for this input ?> http://php.net/manual/en/function.mysql-insert-id.php

« previous php.notes (#141399) next »