My super newb question

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
renaxgade
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2003 4:02 pm

My super newb question

Post by renaxgade »

This is going to seem really stupid, but im stumped.
I have a form name form.html that looks like this:
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="profile.php" method=post>
E-mail:
<br><input type="text" name="email">
<br>
Screen Name:
<br>
<input type="text" name="sm">
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

and a php file called profile.php that looks like this:
<?php
echo "$email";
echo "$sm";
?>

But nothing happens when I enter stuff in the form, it gives me a blank page. Try it at http://68.80.101.77/form.html

Thanks
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

try this:

Code: Select all

<?php
echo "$_POST[email]<br>\n";
echo "$_POST[sm]<br>\n";
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

test this then:
on profile.php:

Code: Select all

<?php

echo $_GET['email'];
echo $_GET['sm'];

?>
when u use GET, PHP save the form varibales and stuff in an array called $_GET[]
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

his form is using the POST method (<form action="profile.php" method="post">)... $_GET will prolly be empty
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

liljester wrote:his form is using the POST method (<form action="profile.php" method="post">)... $_GET will prolly be empty

oops, forgot to mention that :? 8O

ok, ill continue here:
form.html:

Code: Select all

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="profile.php" method="get"&gt;
E-mail:
&lt;br&gt;&lt;input type="text" name="email"&gt;
&lt;br&gt;
Screen Name:
&lt;br&gt;
&lt;input type="text" name="sm"&gt;
&lt;br&gt;
&lt;input type="submit" name="submit" value="submit"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
And then on profile.php:

Code: Select all

<?php

echo $_GET['email'];
echo $_GET['sm'];

?>
If you're just going to to post some strings or numbers or something, use GET instead, POST is better when you're posting big strings, numbers and so on...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

This sounds like a register globals issue, as mentioned above.

Btw it's best not to use "get" as a form method - "post" is slightly more secure.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

McGruff wrote:This sounds like a register globals issue, as mentioned above.

Btw it's best not to use "get" as a form method - "post" is slightly more secure.
nope, but when just submitting email and screen name, i don't think its needed to use POST, but that's renaxgade's choice
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

if post is more secure, is there anything better about get?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you would want to use get if you have an online catalogue of products. Then people will be able to bookmark a specific product page because the query will be saved also.

Mark
Post Reply