eaglealan64 Posted June 23, 2007 Share Posted June 23, 2007 I have a fairly simple application with a form where the user types in some values and I access them from another page via $_POST. The problem I have is that if there are any spaces in the input then everything after the space is lost. I have searched the manual and google and can't find what the issue is. Here is the part of the form which gives the problem: echo ("<th class=\"iteamcell\">Asset Owner:</th><td class=\"itextcell\">"); echo '<select name="assetowner"> '; //Retrieve valid values from the DB and populate the drop down list $queryb = "SELECT ASSETOWNER FROM newcheckvalues WHERE ASSETOWNER <> 'XX' "; $resultb=mysql_query($queryb); $numRowsb=mysql_affected_rows(); if (0==$numRowsb) { echo "<p><em>Error 200 - database in wrong state. Please try again.<em></p>"; } else { #echo "<p><em>Query $queryb ran and produced $numRowsb rows<em></p>"; while ($row=mysql_fetch_array($resultb)) { $myassetowner=$row['ASSETOWNER']; echo "<option value=$myassetowner"; if ($myassetowner==$assetowner) { echo ' selected'; } echo ">$myassetowner</option> "; } } echo '</select></td> '; And here is how I retrieve it: $assetowner=$_POST['assetowner']; Any hints / tips / links etc gladly appreciated. Alan Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/ Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 i am a little bit confused about echo statement. echo "<option value=$myassetowner"; if ($myassetowner==$assetowner) { echo ' selected'; } echo ">$myassetowner</option> "; You use 3 echo here, May i ask for what purpose. Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280774 Share on other sites More sharing options...
eaglealan64 Posted June 23, 2007 Author Share Posted June 23, 2007 i am a little bit confused about echo statement. echo "<option value=$myassetowner"; if ($myassetowner==$assetowner) { echo ' selected'; } echo ">$myassetowner</option> "; You use 3 echo here, May i ask for what purpose. Sure. The first echo prints the <option value> line, the code then checks to see if this value is the current value and if it is it marks it as selected (the second echo), then we round it off by printing the actual value in the form. So the form is populated with all valid values from the database but the current value for this record is defaulted to in the drop down list. HTH Alan Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280777 Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 It means that u have 2 tables where u select the value for 1st table. Try this simple one.but i dont think it will work bcoz u have to select the value from 2nd table. echo "<option value=$myassetowner if ($myassetowner==$assetowner) { selected='Selected'}>$myassetowner</option> "; Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280784 Share on other sites More sharing options...
eaglealan64 Posted June 23, 2007 Author Share Posted June 23, 2007 Thanks. It didn't solve my problem and also broke my code - now the appropriate option is not selected. Do you have any reason why the items after the space aren't being transmitted? Alan Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280789 Share on other sites More sharing options...
AndyB Posted June 23, 2007 Share Posted June 23, 2007 Your problem is caused by bad HTML. The value in an option statement needs to be inside quotes. Try this: $myassetowner=$row['ASSETOWNER']; echo "<option value=". $myassetowner. "' "; if ($myassetowner==$assetowner) { echo "selected='selected'"; } echo ">". $myassetowner. "</option>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280802 Share on other sites More sharing options...
wildteen88 Posted June 23, 2007 Share Posted June 23, 2007 Try: <?php echo '<th class="iteamcell">Asset Owner:</th> <td class="itextcell"> <select name="assetowner">'; //Retrieve valid values from the DB and populate the drop down list $queryb = "SELECT ASSETOWNER FROM newcheckvalues WHERE ASSETOWNER <> 'XX' "; $resultb = mysql_query($queryb); if (mysql_num_rows($resultb) == 0) { echo '<p><em>Error 200 - database in wrong state. Please try again.<em></p>'; } else { // echo '<p><em>Query $queryb ran and produced $numRowsb rows<em></p>'; while ($row = mysql_fetch_assoc($resultb)) { $myassetowner = $row['ASSETOWNER']; $selected = ($myassetowner == $assetowner) ? 'selected' : ''; echo '<option value="' . $myassetowner . '"' . $selected . '>' . $myassetowner . '</option>'; } } echo '</select></td>'; ?> You must surround html attribute values with quotes. Otherwise if attribute values contains spaces the the browser will treat each ground of characters after spaces as separate attributes and not a whole string and thus you think your spaces are being lost. Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280803 Share on other sites More sharing options...
eaglealan64 Posted June 23, 2007 Author Share Posted June 23, 2007 Cheers guy - that was it. Quote Link to comment https://forums.phpfreaks.com/topic/56825-solved-spaces-dont-transfer-via-_post/#findComment-280808 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.