Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

php problem

how to use array contents in form?



7:23 am on Feb 22, 2001 (gmt 0)

I have a couple of array elements which contain 2-3 word strings. I tried to use the contents of these elements as the default value of a text input box, but only the first word appears.

for example if $my_array[0] = 15th of February, only '15th' appears when I try to use it in the way I mentioned (<input type=text name=date value=$my_array[0]>) I also tried to use array element in mailto link for subject and had same problem.


10:18 am on Feb 22, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hi anton, welcome to Webmaster World.

The problem is in your HTML rather than the PHP. You need to enclose $my_array[0] in quotes, or the other words following '15th' will be treated as tag attributes by the browser.

print("<input type=\"text\" name=\"date\" value=\"$my_array[0]\">");
will do the trick - note that the "s are 'escaped' by using a backslash before them to avoid syntax errors.


2:14 pm on Feb 22, 2001 (gmt 0)

Thanks, that did the trick, but I also want to use an array element in a mailto link eg mailto:$my_array[2]?subject=$my_array[3]

I tried enclosing these in escaped quotes but it still didn't work. Any idea on this one?

Thanks heaps for your help...


8:55 pm on Feb 22, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hmm... first of all I'm assuming the content of $my_array[2] is a valid email address?

It's a good idea to get into the habit of enclosing all HTML attribute values in quotes, as it's required in XML and XTML which is where we're all heading eventually... so, your line would look something like:

<? print("<a href=\"mailto:$my_array[2]?subject=$my_array[3]\">"); ?>

Does that work for you?


12:33 am on Feb 23, 2001 (gmt 0)

Yes, that fixed it. I've just got into the habit of not using quotes because I've been able to get away with it so often with HTML.

Thanks heaps :-)


Featured Threads

Hot Threads This Week

Hot Threads This Month