homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Populated a form from a table
why should spaces cause a problem

 12:50 pm on Mar 6, 2002 (gmt 0)


I'm filling a form from a MySQL table using PHP. Everyone is fine except for the instances where the field has a space (eg. the address).
If the value on the table is :
1 Main Street
all I get in the form field is :

the code I'm using is:
<input type=Text name=address1 SIZE=30 VALUE=$myrow[address1]>

nothing unusual there is there ?

I hope somebody can help 'cos there's much scratching of heads here :)



 1:04 pm on Mar 6, 2002 (gmt 0)

The problem's in the HTML - if you put quotes around the value it should be fine.


 1:15 pm on Mar 6, 2002 (gmt 0)

Nope. That doesn't work either, and it's not an HTML problem because the table is within the <?php tag


 1:20 pm on Mar 6, 2002 (gmt 0)

Well, if $myrow[address1] is 1 Main Street, you end up with this HTML:

<input type=Text name=address1 SIZE=30 VALUE=1 Main Street>

The browser only sees the '1' as the value - the spaces make it look to the browser as if Main and Street are extra attributes to the input tag, and as it doesn't recognise them, it just ignores them :)

Changing the code to:
<input type=Text name=address1 SIZE=30 VALUE="$myrow[address1]">

will result in

<input type=Text name=address1 SIZE=30 VALUE="1 Main Street">

being generated, and all will be well...


 1:28 pm on Mar 6, 2002 (gmt 0)

aah! I'd forgotten I need to place a / before the quotes to let PHP know the quotes are valid.

Thanks a lot sugarkane.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved