Figured it out 🙂 Here's a little test script I made to try it using Get.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<form action="#" method="get" name="test">
test1 <input type="text" name="testOne" /><br />
test2 <input type="text" name="testTwo" /><br />
test3 <input type="Text" name="testThree" /><br />
<select name="testSelect">
<option value="none">None</option>
<option value="Bananas">Bananas</option>
<option value="Salad">Chinese Chicken Salad</option>
</select><br /><br />
<input name="action" type="submit" id="action" value="Search" />
</form>
<br /><br />
<?php
// Get variables
$test1 = $_GET['testOne'];
$test2 = $_GET['testTwo'];
$test3 = $_GET['testThree'];
$testSelect = $_GET['testSelect'];
// if none of the fields are in initialized, let the user know
if(!isset($test1, $test2, $test3, $testSelect)){
echo "Please fill out the form.";
} else { // if the fields have been initialized
// if test1 contains nothing, change the link variable to reflect that.
if($test1 == "") {
$link_test1 = "";
echo "<strong>test1 deleted.</strong><br />";
} else { // if test1 contains something, change the link variable to reflect it.
echo "<strong>test1 recieved. ($test1)</strong><br />";
$link_test1 = "test1=$test1";
}
if($test2 == "") {
$link_test2 = "";
echo "<strong>test2 deleted.</strong><br />";
} else {
echo "<strong>test2 recieved. ($test2)</strong><br />";
// if test1's link variable is empty, test2's link doesn't need an & at the beginning.
if ($link_test1 == ""){
$link_test2 = "test2=$test2";
} else { // if test1's link variable ISN'T empty, test2's link DOES need an & at the beginning.
$link_test2 = "&test2=$test2";
}
}
if($test3 == "") {
$link_test3 = "";
echo "<strong>test3 deleted.</strong><br />";
} else {
echo "<strong>test3 recieved. ($test3)</strong><br />";
if ($link_test1 == "" && $link_test2 == ""){
$link_test3 = "test3=$test3";
} else {
$link_test3 = "&test3=$test3";
}
}
if($testSelect == "none") {
$link_testSelect = "";
echo "<strong>testSelect deleted.</strong><br />";
} else {
echo "<strong>testSelect recieved. ($testSelect)</strong><br />";
if ($link_test1 == "" && $link_test2 == "" && $link_test3 == ""){
$link_testSelect = "testSelect=$testSelect";
} else {
$link_testSelect = "&testSelect=$testSelect";
}
}
// Get all variable links and append them onto the final link.
$link = "?$link_test1$link_test2$link_test3$link_testSelect";
// If not redirecting, print final link.
echo "link: <a href='http://localhost/get_test/getTest.php$link'>http://localhost/get_test/getTest.php$link</a>";
// If redirecting, redirect to the link.
/* header("Location: http://localhost/get_test/getTest.php$link");
exit;
*/
}
?>
</body>
</html>
Now if I was using POST I would NOT use the exit statement after header and then I would be able to access all of those variables still correct?
And if there is a more efficient way of doing what my script does that can someone please let me know so I can learn how to make my code more efficient?