I have a form where the admins can enter in a game, one of the fields is called trophies and you enter a number for that field. When the form is submitted I want to be able to insert that amount of blank rows into my trophies database. so for example Game A has 45 trophies I want to insert 45 rows into my trophy database with the game_id being the only value in the row then later on I will fill in the other information
you must have a check for bank fields before submitting forms. you can do this with java scripts as well. because when u load or refresh a webpage that have no check like this. Always insert blank data in database, because code is executed as u refresh u page
//Get the posted form values $gameid = $_POST['gameid']; $trophies = $_POST['trophies']; //Make sure a game was entered if($gameid) { //Make sure the number of trophies was entered if($trophies) { //Loop for each trophy for($i = 0; $i < $trophies; $i++) { $sql = "INSERT INTO games_table (gameid) VALUES ($gameid)"; //Execute sql statement here //echo $sql . "<br/>"; } } } Code (markup): You probably would want to make sure there aren't any records for this game already in the table, or you will keep adding blank rows every time the form is posted.
So with this if I enter in 45 trophies it will create 45 rows then later on if I go back and change the 45 to 47 will it just add 2 more rows to it
No, this code would add another 47 rows. You will need to get the count of existing rows for the game, and subtract the new trophies from that number (if the new number is greater than the existing row count). Then, you can change the for loop to use the difference between those two.