开发者

Echo autoincrement id doubt

can I print the id, even if it's autoincrement ? Because the way I'm doing I'm using an empty variable for id.

$id= "";

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die ("Não conectou com a base $database");

mysql_query("INSERT 开发者_高级运维INTO table1(id,...)
VALUES ('".$id."',....)")
or die(mysql_error());

mysql_close();

echo "Your id is :";

echo "".$id;

I'm trying to print the id, but it's coming blank. I checked the table and there's an id number there. How can I print it then at?

Thanks for the attention


You can retrieve the last auto-generated id on a connection with mysql_insert_id()

Your sample should look like this:

mysql_query("INSERT INTO table1(...) VALUES (....)")
   or die(mysql_error());

$id=mysql_insert_id();

echo "Your id is : $id";


echo "Blah Blah Blah". mysql_insert_id() ;


First insert a $id into database as 0. Here I am using $id = count and $field will print value

$dbconn = mysql_connect($host,$user,$pass) or die (mysql_error()); // try to connect to database mysql_select_db($db,$dbconn); mysql_query("INSERT INTO counter (count) VALUES (\'0\')"); mysql_close($dbconn);

Then update it

$field) { echo $field; ?>

This will may help you...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜