Brickley Posted November 21, 2008 Share Posted November 21, 2008 Hello all, I have an issue with what should be a simple thing - I insert a php "echo" statement to call up a variable (a short string of several words) for the value of in an html form and the value and the result is truncated at the end of the first word. So for example this line: <input type="text" size="15" name="City" value=<?php echo($City) ?> ><br> calls the variable "$City" that contains the string "Santa Monica" - when the form loads, it displays only the first word - in this case, "Santa" and no space. This page has about 15 forms like that and all the variables I am trying to load - text and numbers - that have a space produce the same result. It doesn't matter if the variable comes from code in the page or is read from a database. Any ideas? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/ Share on other sites More sharing options...
JasonLewis Posted November 21, 2008 Share Posted November 21, 2008 Add talking marks around the PHP part. value="<?php echo $City; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695165 Share on other sites More sharing options...
haku Posted November 21, 2008 Share Posted November 21, 2008 Those are necessary, but that won't stop the output from printing. Without seeing some code, it's almost impossible to say. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695166 Share on other sites More sharing options...
JasonLewis Posted November 21, 2008 Share Posted November 21, 2008 haku, run this code: $var = "Foo Bar"; echo <<<html <input type="text" name="something" value=$var /> html; Think about it, without the talking marks there the first space that is encountered by the browser will be assumed the ending of the value attribute. Viewing the source it'd look like this: <input type="text" name="something" value=Foo Bar /> And only 'Foo' will be displayed in the text box. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695168 Share on other sites More sharing options...
haku Posted November 21, 2008 Share Posted November 21, 2008 Ahh, I get what you are saying. I was thinking of the HTML end - it will still print out. But you were talking about the browser display, where only the first word will display. I think that what the OP was talking about and what you are talking about are the same things here, so OP - listen to Project Fear! The quotes should solve your problem. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695180 Share on other sites More sharing options...
Brickley Posted November 21, 2008 Author Share Posted November 21, 2008 Bingo! Quotes around the PHP code is not something I'd have thought of, but works. I'm not sure I want to know what "OP" stands for. Thanks again! ---------------------------------------------------------------------- Paradox of the day: I have no choice but to believe in free will. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695284 Share on other sites More sharing options...
JasonLewis Posted November 21, 2008 Share Posted November 21, 2008 Don't worry, it only means "Original Poster". Remember my reason as to why putting quotes around the PHP, apart from it being the proper way to do it. Without the talking marks there the first space that is encountered by the browser will be assumed the ending of the value attribute. Your value had a space in it, so only the first word would be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-695902 Share on other sites More sharing options...
Brickley Posted November 22, 2008 Author Share Posted November 22, 2008 Very cool. Thanks again for you help. Quote Link to comment https://forums.phpfreaks.com/topic/133621-solved-html-form-is-truncating-php-text/#findComment-696062 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.