Jump to content

Problems with mysql_insert_id


ChrisMartino

Recommended Posts

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
Share on other sites

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.