Jump to content

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();

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.