gigabyt3r Posted September 10, 2009 Share Posted September 10, 2009 When I select a checkbox, no results are returned so I echoed the variable to the page and its empty which I cant seem to understand why? Here is the PHP code use this here -> [code] //display all roof height vehicles when submit button isnt pressed if (!isset($_POST['Submit'])) { $RoofHeight = "N/A', 'Standard Roof', 'Medium Roof', 'High Roof"; } //N/A Roof Height Only if (isset($_POST['Submit']) && isset($_POST['N/A'])) { $RoofHeight = $RoofHeight."N/A"; } //Standard Roof Only if (isset($_POST['Submit']) && isset($_POST['Standard Roof'])) { // add comma if necessary to separate if (!empty($RoofHeight)) { $RoofHeight = $RoofHeight."', '"; } $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['High Roof'])) { // add comma if necessary to separate if (!empty($RoofHeight)) { $RoofHeight = $RoofHeight."', '"; } $RoofHeight = $RoofHeight."High Roof"; } Thanks in advance and this here -> [/CODE] in the future -zanus Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/ Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Bump anyone? Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915934 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2009 Share Posted September 10, 2009 Which variable? Which checkbox? You have not exactly told or shown anyone here what exactly you are having a problem with. You would need to post your form (where the data that is not working is coming from) and state which part of it is not working (so we know where to start looking for the problem.) Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915951 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Here is the form; <p><strong><u>Roof Height</u></strong></p> <p> <input type="checkbox" name="N/A" value="N/A" /> N/A Roof Height Vehicles </p> <p> <input type="checkbox" name="Standard Roof" value="Standard Roof" /> Standard Roof </p> <p> <input type="checkbox" name="Medium Roof" value="Medium Roof" /> Medium Roof</p> <p> <input type="checkbox" name="High Roof" value="High Roof" /> High Roof And the PHP code //display all roof height vehicles when submit button isnt pressed if (!isset($_POST['Submit'])) { $RoofHeight = "N/A', 'Standard Roof', 'Medium Roof', 'High Roof"; } //N/A Roof Height Only if (isset($_POST['Submit']) && isset($_POST['N/A'])) { q $RoofHeight."N/A"; } //Standard Roof Only if (isset($_POST['Submit']) && isset($_POST['Standard Roof'])) { $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['High Roof'])) { // add comma if necessary to separate if (!empty($RoofHeight)) { $RoofHeight = $RoofHeight."', '"; } $RoofHeight = $RoofHeight."High Roof"; } The variable $RoofHeight does not have a value when I select a checkbox submit the form and echo the variable. If you need anymore information don't hesitate to ask! Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915961 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2009 Share Posted September 10, 2009 That's not a complete form, so nothing is submitted anyway. However, if your actual form does submit data, add the following lines of code so that you can see exactly what data is being received - echo "<pre>"; echo "POST:"; print_r($_POST); echo "</pre>"; You will find that variable names cannot contain spaces and php converts them to underscores _ in the POST field names. Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915980 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Thanks for the reply. I can post the whole form although it is rather large. Also, here is the result from the code you posted POST:Array ( [standard_Roof] => Standard Roof [colour] => [textfield2] => [textfield3] => [textfield4] => [submit] => Submit [orderBy] => `Reg Year` ) Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915984 Share on other sites More sharing options...
keldorn Posted September 10, 2009 Share Posted September 10, 2009 Get rid of the isset($_POST['submit']) I'm guessing you thought you neeeded that. But if you dont have actually have a post variable called "submit" set. Am I right? Also remove the spaces from the name="" attributes. Turn "Standard Roof" to "StandardRoof" Edit: I see you do have a post var being sent called Submit.. But regardless you need to get rid the space(s) in the Input name="" attribute as PFMaBiSmAd said. Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915987 Share on other sites More sharing options...
keldorn Posted September 10, 2009 Share Posted September 10, 2009 Also //N/A Roof Height Only if (isset($_POST['Submit']) && isset($_POST['N/A'])) { q $RoofHeight."N/A"; } Is invalid. What is q? Thats not valid syntax. You might want to check that. Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915991 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Also //N/A Roof Height Only if (isset($_POST['Submit']) && isset($_POST['N/A'])) { q $RoofHeight."N/A"; } Is invalid. What is q? Thats not valid syntax. You might want to check that. Thanks, I removed the spaces in the form name and removed the 'q' don't quite know how it got there! It still isn't working though Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-915993 Share on other sites More sharing options...
keldorn Posted September 10, 2009 Share Posted September 10, 2009 I tried runnng your code on my server and it worked. Except for the $_POST['submit']. I removed that and used the form you provided. (after removing the spaces) and it worked. Can I ask a question. Are you assigning "Submit" to your submit button thinking that it sends a variable called Submit and trying to check for it? The submit button doesn't do that. Its not necessary. Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916000 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2009 Share Posted September 10, 2009 The original posted code had a correct line of code where the q... issue is at. Something was lost in the copy/paste. When you removed the space from the form field names, you need to make the corresponding change to the $_POST variable names. Computers only do exactly what their code tells them to do and making a change where something is produced requires a corresponding change where that something is used. The code I posted with the print_r($_POST); was for you to see what variables and data your form is sending, making it possible for you to produce code that uses those variables and data. Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916001 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Ahh of couse. I changed the $_POST variable names and now when i select a checkbox it returns the roof height to the page but it doesnt actually return any vehciles still? Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916129 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 Bump Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916161 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 After much tweaking and frustration i found that when I select a roof height it doesn't work $query_rsVehicle = "SELECT ID, `Vehicle Registration`, Make, Model, Color, Transmission, `Fuel Type`, Mileage, `Reg Year`, `Image Prefix`, `Key Point 1`, `Key Point 2`, `Key Point 3`, `Key Point 4` FROM vehicles WHERE Model LIKE \"%$Search%\" AND Wheelbase IN ('$Wheelbase') AND `Roof Height` IN ('$RoofHeight')"; but when i take the AND Wheelbase IN ('$Wheelbase') it works! The problem is I need them both to work! Anyone have any idea what the best way around this is? Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916171 Share on other sites More sharing options...
gigabyt3r Posted September 10, 2009 Author Share Posted September 10, 2009 I think its because of if (!isset($_POST['Submit'])) { $Wheelbase = "SWB', 'MWB', 'LWB"; } And of course if you select a roof height then the Submit button is posted although there is no Wheelbase value! It sounds a little confusing but if you dont understand just say and I will try explain better. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916191 Share on other sites More sharing options...
gigabyt3r Posted September 11, 2009 Author Share Posted September 11, 2009 Bump Quote Link to comment https://forums.phpfreaks.com/topic/173755-why-doesnt-my-variable-have-a-value/#findComment-916561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.