Skip navigation links

MySQL Forums :: PHP :: How to wait for INSERT to happen before moving onto next INSERT query?


Advanced Search

How to wait for INSERT to happen before moving onto next INSERT query?
Posted by: Mike Liedike ()
Date: March 15, 2013 02:09PM

I am inserting data into, table1. After this data is inserted I am trying to insert data into table2 to based off table1 data. Table2 has FK from table one that I am referencing. This is how I have my inserts setup up right now (this does not work). Any help on how to clean this up and make it work correctly would be greatly appreciated.

$r = mysqli_query($dbc, "INSERT INTO player(gamedate, home, away, goalsfor, goalsagainst, yellowcards, redcards) VALUES ('$gamedate','$home','$away','$goalsfor','$goalsagainst','$yellowcards','$redcards')");
if (mysqli_affected_rows($dbc) == 1) {
	echo "Added game successfully";
	$playerid = mysql_insert_id();
	$gameresult = mysqli_query($dbc, "INSERT INTO game(player_id, pposition, pgoalsfor, pgoalsagainst, psog, ppk, pyellowcards, predcards) VALUES ('$playerid','$pposition','$pgoalsfor','$pgoalsagainst','psog','ppk','pyellowcards','predcards')");
	if (mysqli_affected_rows($dbc) == 1) {
		echo "Added Individual Stats successfully";
		mysqli_close();
	}
	else {
		echo "There was an error.  Your stats were not added.";	
		mysqli_close();
	}
	mysqli_close();
}

else {
	echo "There was an error.  Your game was not added.";	
	mysqli_close();
}

Thank you,
Mike

Options: ReplyQuote


Subject Written By Posted
How to wait for INSERT to happen before moving onto next INSERT query? Mike Liedike 03/15/2013 02:09PM
Re: How to wait for INSERT to happen before moving onto next INSERT query? Peter Brawley 03/15/2013 03:14PM
Re: How to wait for INSERT to happen before moving onto next INSERT query? Barry Galbraith 03/15/2013 05:57PM
Re: How to wait for INSERT to happen before moving onto next INSERT query? Mike Liedike 03/15/2013 06:24PM
Re: How to wait for INSERT to happen before moving onto next INSERT query? Barry Galbraith 03/15/2013 09:45PM
Re: How to wait for INSERT to happen before moving onto next INSERT query? Mike Liedike 03/16/2013 07:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.