Welcome to WebmasterWorld Guest from 107.22.14.254

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Populated a form from a table

why should spaces cause a problem

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

10+ Year Member



Hi,

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 :
1

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)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



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

Thanks a lot sugarkane.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month