Bradley99 Posted June 27, 2012 Share Posted June 27, 2012 Hi, I'm having trouble with having 2 if ($_POST['Submit']){ forms in 1 file. I have two forms(tables) in the file, Both of which update the same table but in different ways. So for example. Form 1 INSERTS into the first 9 columns dependant on what is picked from the form then the rest of the columns are set to default. And form 2 INSERTS a new row but only inserts into the last 4 columns, again dependant on what is picked from the form, with the other columns set to default. But what is happening when I hit 'Submit' on EITHER of the forms, It is creating 2 new rows, one with the info from the form I submitted, and 1 that is all defaults values from the second if ($_POST['Submit']){ form. Here's my code. if ($_POST['Submit']){ $viewevent = $_POST['event_id']; $fight_id = $_POST['fight_id']; $fighter_id = $_POST['fighter_id']; $method = $_POST['method']; $round = $_POST['round']; $bonus = $_POST['bonus']; $fotn_id = $_POST['fotn_id']; $sotn_id = $_POST['sotn_id']; $kootn_id = $_POST['kootn_id']; { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`) VALUES ('', '$fetch->id', '$fight_id', '$user->id', '$fighter_id', '$method','$round','$bonus')") or die (mysql_error()); echo "You picked $fighter_id, Good Luck!"; } { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`, `fotn_id`, `sotn_id`, `kootn_id`) VALUES ('', '$fetch->id', '0', '$user->id', '0', '0', '0', '0', '$fotn_id', '$sotn_id', '$kootn_id' )") or die (mysql_error()); echo "You picked $fighter_id, Good Luck!"; }} ?> I did try having the second forms PHP AFTER the first forms HTML, but that produces the same result. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/264908-having-2-if-post-submit-in-1-file/ Share on other sites More sharing options...
KevinM1 Posted June 27, 2012 Share Posted June 27, 2012 Just give both forms unique input names. submit1 and submit2 would work. Just be aware that you'll need to do two checks, and handle one form or the other based on that check. Quote Link to comment https://forums.phpfreaks.com/topic/264908-having-2-if-post-submit-in-1-file/#findComment-1357574 Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 Thanks, I did try that but used Submit & submit (capital change) but didn't work, Submit1 & Submit2 does. Cheers. Would you know by anychance why when I submit the second form, the page reloads back to where it was, but if i submit the second form i get just an echo? Quote Link to comment https://forums.phpfreaks.com/topic/264908-having-2-if-post-submit-in-1-file/#findComment-1357584 Share on other sites More sharing options...
Barand Posted June 28, 2012 Share Posted June 28, 2012 I'd give the submit buttons different values, say Submit 1 and Submit 2. Then if ($_POST['submit'] == 'Submit 1' // insert first else // insert second Quote Link to comment https://forums.phpfreaks.com/topic/264908-having-2-if-post-submit-in-1-file/#findComment-1357657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.