Jump to content

Whats wrong with my query?


gigabyt3r

Recommended Posts

I am trying to get this query to show the appropriate ticked vehicle roof height, unless no boxs are ticked then I want it to display all vehicle roof heights. However it doesn't work correctly, for example if i tick the Standard roof Height checkbox then submit the form and echo the $RoofHeight to the page I get:

 

N/A', 'Standard Roof', 'Medium Roof', 'High Roof

 

The same goes if I check the medium or high roof buttons.

 

If I tick the N/A button then it just returns "N/A", so why does it work for 1 tickbox but not the others?

 

Here is my PHP code;

 

 

//display all roof height vehicles when submit button isnt pressed
if (!isset($_POST['N/ARoofHeight']) && (!$_POST['Standard Roof']) && (!$_POST['Medium Roof']) && (!$_POST['High Roof'])) {
$RoofHeight = "N/A', 'Standard Roof', 'Medium Roof', 'High Roof";
}





//N/A Roof Height Only
if (isset($_POST['Submit']) && isset($_POST['N/ARoofHeight'])) {
$RoofHeight = $RoofHeight."N/A";
}



//Standard Roof Only 
if (isset($_POST['Submit']) && isset($_POST['Standard Roof'])) {
$RoofHeight = $RoofHeight."Standard Roof";
}

//Medium Roof Only
if (isset($_POST['Submit']) && isset($_POST['Medium Roof'])) {
// add comma if necessary to separate
if (!empty($RoofHeight))
{
$RoofHeight = $RoofHeight."', '";
}
$RoofHeight = $RoofHeight."Medium Roof";
} 


//High Roof ONLY
if (isset($_POST['Submit']) && isset($_POST['HighRoof'])) {
// add comma if necessary to separate

if (!empty($RoofHeight))
{
$RoofHeight = $RoofHeight."', '";
}
$RoofHeight = $RoofHeight."HighRoof";
} 

 

 

Can anyone see whats wrong with it?

 

Thanks in advance  :confused:

Link to comment
https://forums.phpfreaks.com/topic/179517-whats-wrong-with-my-query/
Share on other sites

try this...

 

//display all roof height vehicles when submit button isnt pressed
if (!$_POST['N/ARoofHeight'] && !$_POST['Standard Roof'] && !$_POST['Medium Roof'] && !$_POST['High Roof']) {
$RoofHeight = "N/A', 'Standard Roof', 'Medium Roof', 'High Roof";
}

You also might want to avoid using spaces and slashes in names...

try this...

 

//display all roof height vehicles when submit button isnt pressed
if (!$_POST['N/ARoofHeight'] && !$_POST['Standard Roof'] && !$_POST['Medium Roof'] && !$_POST['High Roof']) {
$RoofHeight = "N/A', 'Standard Roof', 'Medium Roof', 'High Roof";
}

You also might want to avoid using spaces and slashes in names...

 

I tried that bit of code and it worked when i just selected the N/A Roof Height but when i selected standard or medium etc then it returned all the roof heights same as before!

 

Any ideas why it wont work?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.