BCAV_WEB Posted October 8, 2010 Share Posted October 8, 2010 I have a form which has a drop down menu select box, which retrives the makes of cars from a database, which once clicked submit will go to another page post that info. Then a if statment says if the variable that has been posted == a certain word that matches the one in the database then display content. However, my issue is when I have a car make such as "Land Rover" saved in the database as typed it just comes back with the final else statement. In the 1st section I have included the form which is posting the information across and in the second I have the if statement. Any ideas of how to get around / make this work? [ <form method=post" action="details.php" enctype="multipart/form-data"> <table class="search_nav"> <tr> <td> <select name="manufacture" id="manufacture"> <option value=" " selected="selected">Car Manufactures </option> '; $query = "SELECT DISTINCT make FROM cars ORDER BY make ASC"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); while ($row = @ mysql_fetch_array($result)) { print ' <option value='.$row["make].'>'.$row["make"].'</option> '; } print ' </select> </td> </tr> <tr> <td colspan="2"> <input type="image" src="images/go.gif" alt="Go" name="submit" id="submit" value="Submit"/> </td> </tr> </table> </form> ] [ if ($manufactures == "Land Rover") { echo "test"; } ] Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2010 Share Posted October 8, 2010 Where is your code that is setting $manufactures ? Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1120149 Share on other sites More sharing options...
BCAV_WEB Posted October 8, 2010 Author Share Posted October 8, 2010 I have manually enetered the data into the database, so the select is coming as the word "Land Rover" and the value should also be "Land Rover" and this information is then posted in the form under the id "manufactures". I have over makes working such as Ford and have recently changed the land rover to "Land-Rover" both on the if statement and in the database, which works fine. The issue is to do with the space, I have also tried using " " which also hasn't worked Any Ideas?? Database Structure [ id int(10) make varchar(40) make_link varchar(25) rrp varchar(10) what_price int( what_link varchar(1000) our_price varchar( image varchar(100) ] Data [ 6 Land Rover ] Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1120216 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2010 Share Posted October 8, 2010 Your select menu has name="manufacture". The submitted value would be in $_POST['manufacture'] Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1120226 Share on other sites More sharing options...
BCAV_WEB Posted October 11, 2010 Author Share Posted October 11, 2010 Yes that is correct and it works like for most cases however, when it submits "Land Rover" and retrives the word "Land Rover" from the database it doesn't seem to work for some reason. Resulting in the final else statement, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121004 Share on other sites More sharing options...
PFMaBiSmAd Posted October 11, 2010 Share Posted October 11, 2010 Your HTML is invalid/broken. You need quotes (either single or double) around the value="..." attribute. Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121042 Share on other sites More sharing options...
BCAV_WEB Posted October 11, 2010 Author Share Posted October 11, 2010 what you mean here : <option value='.$row["make"].'>'.$row["make"].'</option> it has single quotation marks, and why would it work for "Ford" for example?? Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121043 Share on other sites More sharing options...
Pikachu2000 Posted October 11, 2010 Share Posted October 11, 2010 No, it doesn't have any quotes. Look at the output in the html (view source) and you'll see what PFMaBiSmAd means. Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121046 Share on other sites More sharing options...
PFMaBiSmAd Posted October 11, 2010 Share Posted October 11, 2010 Those quotes are part of the php code that is making a string. They are not part of the HTML that is output. Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121047 Share on other sites More sharing options...
BCAV_WEB Posted October 11, 2010 Author Share Posted October 11, 2010 So should it be: [<option value= '.$row["make].' ">'.$row["make"].'</option>] Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121048 Share on other sites More sharing options...
PFMaBiSmAd Posted October 11, 2010 Share Posted October 11, 2010 Yes, but that would also add a space character before and after the value. Remove the extra space between the first " and the ' and the ' and the next ". Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121050 Share on other sites More sharing options...
BCAV_WEB Posted October 11, 2010 Author Share Posted October 11, 2010 Yes the coding doesnt have that, I only put in the space for you guys to see and it still isn't working Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121052 Share on other sites More sharing options...
BCAV_WEB Posted October 11, 2010 Author Share Posted October 11, 2010 My bad, I forgot to change the if statement from "land-rover" which was my temp fix and it works fine now. Thank you very much people :D :D Once again someone else on this forum has come to my rescue :D:D:D Quote Link to comment https://forums.phpfreaks.com/topic/215418-mysql-spaces/#findComment-1121053 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.