makamo66 Posted November 16, 2019 Share Posted November 16, 2019 The file test2.php consists of these simple forms: <?php for($i=0; $i<=5; $i++){ echo "<form action='reset4.php' method='get' name='yourForm'>"; echo "<button type='submit' value='delete' name='remove_" . $i . "' class='deletebtn'>X</button>"; echo "</form>"; } ?> It submits to reset4.php which is this simple code: <?php header("Location: test2.php"); exit; for($i=0; $i<=5; $i++){ if (isset($_REQUEST["remove_$i"])){ echo "Deleted"; }} ?> But it doesn't work. The $_REQUEST doesn't populate the address field and it apparently never gets submitted to reset4.php like it should. This is such a simple program, I can't imagine why it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/ Share on other sites More sharing options...
benanamen Posted November 16, 2019 Share Posted November 16, 2019 The first thing you do is issue a redirect and kill the script. How do you expect it to do anything after that? Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571601 Share on other sites More sharing options...
makamo66 Posted November 16, 2019 Author Share Posted November 16, 2019 When I remove exit it still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571605 Share on other sites More sharing options...
ginerjm Posted November 16, 2019 Share Posted November 16, 2019 Why do you begin the second script with a leap to ANOTHER script? Makes no sense at all. Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571606 Share on other sites More sharing options...
makamo66 Posted November 16, 2019 Author Share Posted November 16, 2019 When I do the following, it still doesn't work: <?php for($i=0; $i<=5; $i++){ echo "<form action='' method='get' name='yourForm'>"; echo "<button type='submit' value='remove_" . $i . "' name='delete' class='deletebtn'>X</button>"; echo "</form>"; } for($i=0; $i<=5; $i++){ if (isset($_REQUEST["remove_$i"])){ echo "delete"; echo "Received Value: " . $_REQUEST["remove_$i"]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571610 Share on other sites More sharing options...
NotSunfighter Posted November 16, 2019 Share Posted November 16, 2019 Your problem is in the reset4.php file remove both of these line: header("Location: test2.php"); exit; The problem you started with is the file test2.php - your running this instead of reset4.php Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571615 Share on other sites More sharing options...
Barand Posted November 16, 2019 Share Posted November 16, 2019 When your button's name is "delete" why are you checking for $_REQUEST["remove_$i"] instead of $_REQUEST['delete'] ? Stop using REQUEST. Use POST or GET depending on your form's method. if you are fetching data to display, use method GET. If submitting your form has consequences (such as updating, deleting, emailing) then use POST method. Quote Link to comment https://forums.phpfreaks.com/topic/309532-simple-form-submission-doesnt-work/#findComment-1571619 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.