Quantcast
Channel: MySQL Forums - PHP
Viewing all articles
Browse latest Browse all 938

How to wait for INSERT to happen before moving onto next INSERT query? (5 replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>