function teams() {
if ( !isset($_POST['year']) ? $year='2011' : $year=$_POST['year'] );
if ( !isset($_POST['state']) ? $state='KS' : $state=$_POST['state'] );
if ( !isset($_POST['sport']) ? $sport=1 : $sport=$_POST['sport'] );
$page = <<<END
<form action="admin.php?do=teams" method="post">
How do I get the information from my first link to work with the $_POST in this last one? It works great if you go through the FORM or start from scratch, but how would I pass values from another function and have it recognize them, if it is possible?
First thing is first and that is your HTML for the anchor link is invalid, you can’t use double quotes " within an attribute that’s wrapped with double quotes as it causes a break in the code. The below HTML is valid and won’t cause any errors:
I am a little confused though as to how you didn’t find your answer to your question on Google or another search engine as it’s dead simple and the opposite of using $_POST, please see the below code which uses $_GET to grab the values from the URL and is less complex them what you currently have as you don’t need to declare the variables within a ternary operator.
The code i posted above uses what’s called a ternary operator which is a short way of saying “shorthand if statement”, basically the question mark ? is the IF statement and the semicolon : is the ELSE statement. Unlike a regular IF statement which can become quite long and unpleasing to the eye a ternary operator is a lot shorter but allows for the same basic concept.
In the above code the following is happening:
I set the variable in which the value will be set to
I check if the $_POST value exists otherwise continue to the next ternary operator
If the $_GET value exists it gets set otherwise it defaults to a static value
So essentially it’s exactly the same as the following example: