Reputation: 478
I am totally stuck here and found tens of samples on posting to get and set values. What I am trying to do is -
Let a user enter a vehicles year model into a textbox in my form
I then need to get this value to a variable state
$vehicle_year = $_GET['vyear'];
First error is here... vyear is the name and id for my textbox. There is NO submission of the form etc, because I am still on the same form/page. As per my code below, I can check if a value does NOT exist... How do I get the actual entered value back?
$vehicle_year = isset($_POST['vehicleyear']) ? $_POST['vehicleyear'] : -1;
if ($vehicle_year == -1) {
echo 'No Value Returned...';
//returns no value...
} else {
//How to get the value and echo it out...
echo $vehicle_year;
}
With this value captured, I then search my database to return all of the manufacturers that has a year (as returned) attached to it -
$query = "SELECT * FROM `vehicledata` WHERE `year`='$vehicle_year'";
Obviously it does not work because I still do not have the value as yet returned.
Upvotes: 0
Views: 159
Reputation: 62
You can check whether there is any POST/GET submission data by using print_r() or var_dump() to display the contents of $_POST or $_GET, but like relentless said, it looks like you are mixing those two up.
Related:
Don't use -1, but FALSE/NULL if you want to indicate something is not available. You can use the identical operator === to make sure you don't get false positives if the value you are checking for is 0.
DON'T insert user-submitted values into your query directly. If you don't sanitize them first, your site will be vulnerable to SQL injection attacks.
Upvotes: 1