kristian_gl Posted May 3, 2010 Share Posted May 3, 2010 preview.php: <form id="form100" name="form100" method="POST" action="preview.php"> <input type="submit" name="back" id="tilbake" value="Back" /> <input type="submit" name="finish" id="lagre" value="Finished" /> <input type="submit" name="publish" id="publiser" value="Publish" /> </form> <br /> <?php $finish= $_POST['finish']; $back= $_POST['back']; $publish= $_POST['publish']; if (isset($finish)) { setcookie("navn_cookie", "", time()-3600); header('Location: http://stud.aitel.hist.no/~oddl/admin/admin.php'); } elseif (isset($back)) { header('Location: http://stud.aitel.hist.no/~oddl/admin/leggtilspm.php'); } elseif (isset($publish)) { $drop_table = "DROP TABLE `svar`"; mysql_query($drop_table); $create_table = 'CREATE TABLE `svar` (' . ' `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY' . ' )' . ' ENGINE = myisam;'; mysql_query($create_table); header('Location: http://stud.aitel.hist.no/~oddl/admin/undersokelse.php'); } ?> When I click on any of the submitbuttons, the page just refreshes itself, and doing what I've haved specified in the if-loop Quote Link to comment https://forums.phpfreaks.com/topic/200547-submit-button-dont-work/ Share on other sites More sharing options...
ChemicalBliss Posted May 3, 2010 Share Posted May 3, 2010 Isset checks if the variable has been set or exists, you have set each variable to exist just above the if statement that checks it, it will always return true - and execute. Use if(isset($_POST['finish'])), and if(isset($_POST['back'])) instead. Also, I would use hard links instead though, rather than extra submit buttons (since you don't need to submit data unless your publishing), just like: <form id="form100" name="form100" method="POST" action="preview.php"> <a href="preview.php?action=back">Back</a> <a href="preview.php?action=finish">Finished</a> <input type="submit" name="publish" id="publiser" value="Publish" /> </form> <br /> then just change this <?php if (isset($_GET['finish'])) { setcookie("navn_cookie", "", time()-3600); header('Location: http://stud.aitel.hist.no/~oddl/admin/admin.php'); } elseif (isset($_GET['back'])) { header('Location: http://stud.aitel.hist.no/~oddl/admin/leggtilspm.php'); } elseif (isset($_POST['publish'])) { $drop_table = "DROP TABLE `svar`"; mysql_query($drop_table); $create_table = 'CREATE TABLE `svar` (' . ' `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY' . ' )' . ' ENGINE = myisam;'; mysql_query($create_table); header('Location: http://stud.aitel.hist.no/~oddl/admin/undersokelse.php'); } ?> -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200547-submit-button-dont-work/#findComment-1052332 Share on other sites More sharing options...
siric Posted May 3, 2010 Share Posted May 3, 2010 Works for me. What I would do however is to use the same name for the submit button, but only change the value <input type="submit" name="submit" id="tilbake" value="Back" /> <input type="submit" name="submit" id="lagre" value="Finished" /> <input type="submit" name="submit" id="publiser" value="Publish" /> Then in the preview.php $selection = $_POST['submit']; if ($selection == 'Back') { ... } elseif ($selection == 'Finished') { ..... } elseif ($selection == 'Publish') { ...... } Quote Link to comment https://forums.phpfreaks.com/topic/200547-submit-button-dont-work/#findComment-1052472 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.