View Full Version : Mysterious PHP problem...
Arthur
12-01-2000, 02:53 PM
<? if($state){echo"<option value=$state>$state";}?>
If I understand your code correctly, I think the problem may be solved if you put quotes around $state like so;
<? if($state){echo"<option value=\"$state\">$state";}?>
HTH
Arthur
WayneAH
12-01-2000, 03:06 PM
Jeff,
I'll be interested to see if anyone has a solution for you. I have never been able get a PHP/MySQL query to correctly fill a form field containing multiple words - the string always breaks on the first whitespace.
One inelegant solution is to str_replace whitespaces with "%20". The problem is that the %20 shows up in any form you return users to (e.g., "District%20of%20Columbia"), though it shows as innoccuous whitespace when outputted by html outside a form.
You also might want to look at the source code for PHPMyAdmin. Tobias Ratschiller obviously has figured a way around the break-on-whitespace-inside-a-form problem. I took a look myself, but his coding is beyond my understanding.
Sorry this doesn't help much - but a least you know you're not crazy.:)
Wayne
PaulKroll
12-01-2000, 03:47 PM
Oh, I suspect Arthur's solution is in fact "it", since doing "value=District of Columbia" (remove quotes) in HTML will get you the same result. The reason it looks as if the "of Columbia" is truncated is that the text is still within the <option> tag: if jefbea looks at the resulting source from the browser side, I'd put down money the text is there.
This is an HTML problem: You need to put quotes around the value in a "value=" statement, and if you don't, it's only by the grace of browsers that they accept any of the words at all. (Even "value=1" should actually be 'value="1"')
SneakyDave
12-01-2000, 06:20 PM
One inelegant solution is to str_replace whitespaces with "%20". The problem is that the %20 shows up in any form you return users to (e.g., "District%20of%20Columbia"), though it shows as innoccuous whitespace when outputted by html outside a form.
You can also use the urlencode($variable) and urldecode($variable) functions so that all special characters like spaces, quotes, double quotes, can be used.
Something like:
print '<input type=text name=state value="'.urlencode($state).'">';
The code above might work if it was written:
<? if($state){echo"<option value='".urlencode($state)."'>$state";}?>
[This message has been edited by SneakyDave (edited 12-01-00@5:24 pm)]
jefbea
12-02-2000, 01:32 AM
I am not a very good PHP programmer, but I am getting better... I've got this code I was hoping someone could look at and maybe suggest a fix for me (this code is for a classified ad section on my site where people are able to list the state).[nbsp][nbsp]The problem is this:
When someone posts an ad, they must select their state.[nbsp][nbsp]States with two words (i.e. New York, New Jersey, District of Columbia) are giving me a problem.[nbsp][nbsp]When they initially post their ad, as long as they have filled in all the fields properly, there are no problems.[nbsp][nbsp]If they forget to fill in a field (like their city, for example), that's when the problem occurs.[nbsp][nbsp]The code re-prints the state they live in, but instead of printing the full name of the state (i.e. District of Columbia), it will only echo the word "District", truncating the "of Columbia".
I hope explained that right...
Here are the two sections of code I believe are pertinent:
[SECTION 1]
<?
if (!$state)
{
echo"<FONT COLOR='#FF0000'>State:&nbsp;</FONT>";
}
elseif($state){
$bad=false;
for( $i = 0; $i < $array_size; $i++ )
if( eregi($cuswords[$i], $price)) {
$bad=true;
}
if($bad)
{
print("<FONT COLOR='#FF0000'>State:&nbsp;</FONT>");
}
else
{
echo"State:&nbsp;";
}
}
?>
[SECTION 2]
<? if($state){echo"<option value=$state>$state";}?>
So I guess my question is, do you see any problems with this code?[nbsp][nbsp]Can you suggest any changes that might fix this?
Thanks again for any help.
Jeff
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.