Help With Using PHP to echo a html form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrgooding
Forum Newbie
Posts: 23
Joined: Thu May 22, 2008 11:45 am

Help With Using PHP to echo a html form

Post by mrgooding »

Hi All

I'm having trouble making what should be a simple update form:

Code: Select all

 
echo "<form action='editcontact.php' method='POST'>";
         echo "<input type='hidden' name='id' value= '$editrow["c_id"]'>; 
         echo "<input type='text' name='name'  size='20' value='$editrow["c_forename"]'>; 
         echo "<input type='text' name='address' size='40' value='$editrow["c_surname"]'>;
         echo "<input type='submit'  name='submit' value='submit'>"; 
         echo "</form>"; 
 
 
Is the bit of code thats causing a problem - i'm not sure what the error is, but I know it's in this bit of code (i'm working on a remote server which unfortunately has error messages turned off)

All of the strings within the $editrow array work fine when I echo them normally, but when I try and output them in this form, it all goes wrong!

Any pointers as to why the above code might not work? Any help would be gratefully received.
For future reference, please use the BBcode tags to enclose any code you post, as I have done for you, above.
Dj_Lord
Forum Newbie
Posts: 6
Joined: Mon Jun 16, 2008 11:51 am

Re: Help With Using PHP to echo a html form

Post by Dj_Lord »

try this:

Code: Select all

echo "<form action='editcontact.php' method='POST'>";
echo "<input type='hidden' name='id' value= '".$editrow['c_id']."'>"; 
echo "<input type='text' name='name' size='20' value='".$editrow['c_forename']."'>"; 
echo "<input type='text' name='address' size='40' value='".$editrow["c_surname"]."'>"; 
echo "<input type='submit' name='submit' value='submit'>"; 
echo "</form>";
Last edited by Dj_Lord on Mon Jun 16, 2008 1:31 pm, edited 1 time in total.
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Help With Using PHP to echo a html form

Post by Frozenlight777 »

When you're outputting html through php, try and remove the quotes.
so for all your lines try doing this...

echo "<form action=editcontact.php method=POST>";
instead of
echo "<form action='editcontact.php' method='POST'>";

I have a few other ideas.. but if that doesn't work let me know.

and also what dj said, try and concatenating the arrays.
mrgooding
Forum Newbie
Posts: 23
Joined: Thu May 22, 2008 11:45 am

Re: Help With Using PHP to echo a html form

Post by mrgooding »

Brilliant, that's solved it thanks!

Many thanks to you both :D
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help With Using PHP to echo a html form

Post by califdon »

mrgooding wrote:

Code: Select all

 
echo "<input type='hidden' name='id' value= '$editrow["c_id"]'>; 
echo "<input type='text' name='name'  size='20' value='$editrow["c_forename"]'>; 
echo "<input type='text' name='address' size='40' value='$editrow["c_surname"]'>;
 
 
In the 3 lines of code above, you have prematurely ended the double-quoted string and the closing bracket for the input tag is missing a double-quote. That's why it is failing. The correct syntax is:

Code: Select all

 
echo "<input type='hidden' name='id' value= '".$editrow['c_id']."'>"; 
echo "<input type='text' name='name'  size='20' value='".$editrow['c_forename']."'>"; 
echo "<input type='text' name='address' size='40' value='".$editrow['c_surname']."'>";
 
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help With Using PHP to echo a html form

Post by John Cartwright »

Frozenlight777 wrote:When you're outputting html through php, try and remove the quotes.
so for all your lines try doing this...

echo "<form action=editcontact.php method=POST>";
instead of
echo "<form action='editcontact.php' method='POST'>";

I have a few other ideas.. but if that doesn't work let me know.

and also what dj said, try and concatenating the arrays.
Sorry to say, that is bad advice. You should always quote your html attributes.
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Help With Using PHP to echo a html form

Post by Frozenlight777 »

Good to know. Any explanation why?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help With Using PHP to echo a html form

Post by John Cartwright »

What if there is a space in the attribute value?
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Help With Using PHP to echo a html form

Post by Frozenlight777 »

touché, never thought of that.
mrgooding
Forum Newbie
Posts: 23
Joined: Thu May 22, 2008 11:45 am

Re: Help With Using PHP to echo a html form

Post by mrgooding »

Thanks for the info all, I appreciate it :)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Help With Using PHP to echo a html form

Post by Ambush Commander »

While there are some schools of thought that say that unquoted attributes are valid forms of expression, you can cover your ass against a slew of security attacks and whatnot by properly quoting your attribute values. Don't forget to escape!
Post Reply