Jump to content

[SOLVED] Spaces don't transfer via $_POST


eaglealan64

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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> ";

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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