Jump to content

Simple Form Submission Doesn't Work


makamo66

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. 

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

?>

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.