note 84376 added to function.mysql-insert-id
| From: | neep03 at zonnet dot nl | Date: | Thu, 10 Jul 2008 20:52:14 +0000 |
| Subject: | note 84376 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141389@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
?>
----
Server IP: 213.249.64.162
Probable Submitter: 87.208.97.195
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- https://master.php.net/note/edit/84376
Del: integrated -- https://master.php.net/note/delete/84376/integrated
Del: useless -- https://master.php.net/note/delete/84376/useless
Del: bad code -- https://master.php.net/note/delete/84376/bad+code
Del: spam -- https://master.php.net/note/delete/84376/spam
Del: non-english -- https://master.php.net/note/delete/84376/non-english
Del: in docs -- https://master.php.net/note/delete/84376/in+docs
Del: other reasons-- https://master.php.net/note/delete/84376
Reject -- https://master.php.net/note/reject/84376
Search -- https://master.php.net/manage/user-notes.php