Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Easy Form Code

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Easy Form Code

Postby wfsaxton » Wed Feb 19, 2003 5:12 pm

Anyone see a problem with this? The purpose is to simply print back all of the submitted information. Instead, it simply "refreshes" the page. My guess is that it doesn't see the $submit variable, which "echo $submit" attests to. Anyone know why this is?

<html>
<body>

<?php
if ($submit) {
while (list($name, $value) = each($_POST)) {
echo "$name = $value<br>\n";
}
} else {
?>

<form method="POST" action="<?php echo $PHP_SELF?>">

<table width="800" border="1">
<tr>
<td>Blog Name:</td>
<td><input name="blogname" type="text" size="20" maxlength="40"></td>
</tr>
<tr>
<td>Blog Url:</td>
<td><input name="blogurl" type="text" size="20" maxlength="40"></td>
</tr>
<tr>
<td>Your Name:</td>
<td><input name="name" type="text" size="20" maxlength="30"></td>
</tr>
<tr>
<td valign="top">Blog Description:</td>
<td><textarea name="blogdescription" cols="50" rows="4"></textarea></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Add your blog!"></td>
<td>&</td>
</tr>
</table>

</form>
<?php
}
?>

</body>
</html>
wfsaxton
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 19, 2003 5:07 pm
Location: Boston, MA

Postby wfsaxton » Wed Feb 19, 2003 6:46 pm

Gah..I just added

echo $PHP_SELF
echo $submit

and it doesn't print anything. Could this be the problem?
wfsaxton
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 19, 2003 5:07 pm
Location: Boston, MA

Postby wfsaxton » Wed Feb 19, 2003 6:52 pm

K..I'm a dummie. register_globals was set to "off".

Is there a way to do something like this w/o globals? I've heard of various security risks involved in doing it this way.

Also, my past as a C programmer taught me that global variables = crappy programming. Is there a way to do something like this w/o using global variables?
wfsaxton
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 19, 2003 5:07 pm
Location: Boston, MA

Postby Redcircle » Wed Feb 19, 2003 10:09 pm

I'm about to write a tutorial on register_globals. I think that is the number one problem I see people having a problem with on these forums.. I'm kinda sick of trying to explain to people how to do it properly.

What really sucks is most of the tutorials and books out there are teaching people how to code with the mindset of register_globals being on.. I'm going to put my 9mm to my head and end my misery.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.