ChrisMartino Posted August 4, 2010 Share Posted August 4, 2010 Hello there, well basically what this function does is look at all the entry's to find a unused port in the database but when I run the function the first time if the table is empty mysql_insert_id works fine, but then if I run it again the mysql_insert_id keeps returning 0, I am using it immediately after the query but its not working properly, can anybody shed some ideas into the matter, anything is appreciated!, thanks for your time!: function addServerToBuildPool($ServerGame, $ServerOwner, $ServerSlots, $ServerBox) { $Server = mysql_fetch_array(mysql_query("SELECT * FROM xhost_boxs WHERE box_id = '".mysql_real_escape_string($ServerBox)."'")); $AddServer = mysql_query("INSERT INTO xhost_servers (server_game, server_slots, server_owner, server_ip, server_is_setup) VALUES('".mysql_real_escape_string($ServerGame)."', '".mysql_real_escape_string($ServerSlots)."', '".mysql_real_escape_string($ServerOwner)."', '".mysql_real_escape_string($Server['box_ip'])."', 'No')"); $ServerID = mysql_insert_id(); $FindPort = mysql_query("SELECT server_port FROM xhost_servers ORDER BY server_id ASC"); $Port = 0; while($row = mysql_fetch_assoc($FindPort)) { $Port = ($Port == 0)? $row['server_port'] : $Port; if($row['server_port'] != $Port) { break; } $Port++; } mysql_query("UPDATE xhost_servers SET server_port = '".$Port."' AND server_username = 'server".$ServerID."' AND server_password = '".rand(5000000, 900000000)."' WHERE server_id = '".$ServerID."'") or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/209819-problems-with-mysql_insert_id/ Share on other sites More sharing options...
Mchl Posted August 4, 2010 Share Posted August 4, 2010 Is there an AUTO_INCREMENT primary key field in this table? Link to comment https://forums.phpfreaks.com/topic/209819-problems-with-mysql_insert_id/#findComment-1095253 Share on other sites More sharing options...
ChrisMartino Posted August 4, 2010 Author Share Posted August 4, 2010 Is there an AUTO_INCREMENT primary key field in this table? Sure is Link to comment https://forums.phpfreaks.com/topic/209819-problems-with-mysql_insert_id/#findComment-1095254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.