Page 1 of 1
Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 12:50 pm
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.
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 12:53 pm
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>";
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 12:58 pm
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.
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 1:16 pm
by mrgooding
Brilliant, that's solved it thanks!
Many thanks to you both

Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 1:20 pm
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']."'>";
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 1:35 pm
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.
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 1:57 pm
by Frozenlight777
Good to know. Any explanation why?
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 2:06 pm
by John Cartwright
What if there is a space in the attribute value?
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 2:10 pm
by Frozenlight777
touché, never thought of that.
Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 2:59 pm
by mrgooding
Thanks for the info all, I appreciate it

Re: Help With Using PHP to echo a html form
Posted: Mon Jun 16, 2008 4:17 pm
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!