Jump to content

Another quick question


supanoob

Recommended Posts

ok so i have the following insert statement and i would like to know how to get the unique auto increment ID from the row it inserts straight after inserting it. So after inserting it i would like to get the "battle_id" field from the row just inserted, is it possible?

 

<?php

$query="insert into battle_log (defender_id, attacker_id, attacker_ip, defender_ip, attacker_start_health, defender_start_health, battle_time, battle_date) values ('$attack', '$account_id', '$ip_1', '$ip_2', '$health_1', '$health_2', NOW(), NOW())";
$result=mysql_query($query);

?>

 

this thing is i cannot use the player ID's incase they have battled before it would bring multiple results, i need it to bring only 1.

Link to comment
https://forums.phpfreaks.com/topic/68220-another-quick-question/
Share on other sites

i tried that but it didnt work, this is what i did:

 

<?php

$query="insert into battle_log (battle_id, defender_id, attacker_id, attacker_ip, defender_ip, attacker_start_health, defender_start_health, battle_time, battle_date) values ('', '$attack', '$account_id', '$ip_1', '$ip_2', '$health_1', '$health_2', NOW(), NOW())";
$result=mysql_query($query);
$battle_id = mysql_insert_id();

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.