Jump to content
makamo66

Simple Form Submission Doesn't Work

Recommended Posts

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. 

Share this post


Link to post
Share on other sites

The first thing you do is issue a redirect and kill the script. How do you expect it to do anything after that?

Share this post


Link to post
Share on other sites

Why do you begin the second script with a leap to ANOTHER script?  Makes no sense at all.

Share this post


Link to post
Share on other sites

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"];
}
}

?>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.