I have made a PHP script that retrieves a username from a text field, and confirms it using three different buttons, where each button redirects to a different page.
A fellow user gave a solution, it an HTML form with the textfield and three buttons, then an if statement in PHP to determine which button was pressed and it will do the appropriate redirection.
There is a problem, however. This method doesn't seem to pass any form data...
Code:
<!-- Current solution for redirection does NOT pass form data. -->
<?php
echo "<div style = 'font:33px/54px Arial'> StreamViewer</div>";
echo "Please enter your username. If you are not registered, submit and click the add/remove author button once redirected.";
if(isset($_POST['button1']))
{
header('location: page1.php');
}
elseif(isset($_POST['button2']))
{
header('location: page2.php');
}
elseif(isset($_POST['button3']))
{
header('location: page3.php');
}
?>
<br><br>
<form action = "" method = "POST">
Username: <input type = "text" name = "username" value = "">
<br>
<button type = "Submit" name = "button1" value = "b1">b1</button>
<button type = "Submit" name = "button2" value = "b2">b2</button>
<button type = "Submit" name = "button3" value = "b3">b3</button>
</form>
Here is some code from one of the pages that is not receiving the form data:
$username = $_POST['username'];
echo "Hello $username";
The output for this page is simply "Hello ".
echo '<pre>; print_r($_POST);See what you get within this$_POSTarray.