This code does not work right...take a look

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 2:55 am    Post subject: This code does not work right...take a look Reply with quote

Here is a basic code that I can not get to display

this is the HTML

<html>
<head>
<title>My Form</title>
</head>
<body>

<form action="color.php" method=post>

My name is:
<br> <input type="text" name="YourName">

<p> My favorite color is:
<br> <input type="text" name="FavoritColor">
<p>

<input type="submit" name="submit" value="Enter My Data!">
</form>

</body>
</html>

This is the PHP

<html>
<head>
<title>Test!</title>

</head>

<body bgcolor="#FFFFFF" text="#000000">

<p>
Hi <?php print $YourName; ?>

<p>
You like the Color <b> <?php print $FavoriteColor; ?> !?! </b>

<p>You oughta be ashamed of yourself!

</body>
</html>

Now, I know that I have the web server installed correctly because I can print basic statements using php, but why can I not get this code to display the Name and Color from the HTML form to the PHP page? I don't see any errors. Do you?
Back to top View user's profile Send private message
whackaxe
-


Joined: 28 Jun 2003
Posts: 90

PostPosted: Fri Jan 02, 2004 3:35 am    Post subject: Reply with quote

it would seel that you are using obsolete documentation. what you are trying to do here is acces the posted values as globals. this worked up till about PHP 4.0.6 (i think) and then php was set to refusing them by default.

two fixes:
-the bad one: go into php.ini and set register_globals=on this is a BIG security threat because t doenst check where the data is coming from. it could just as well come from an URL string. this scenario could open up all sorts of holes for bother user and you

-the good one: the new way to check your values is with the following arrays
$_POST['name_of_input_field'] and $_GET['name_of_input_field'] i'll let you guess what situation they stand for :p

this in mind. safe coding!
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 3:41 am    Post subject: Thanks...but uh...still help Reply with quote

I appericate you help, but the thing is, I have no clue what your talking about. I would like to create a login for an HTML form where you can login into an account, but I am in the process of learning php, I checked out www.webmonkey.com and that is where I got that basic script to display that neat little php code. What else, or where else can I go to learn and understand how to create what I am trying to do? As Programmer said in his post. I too am trying to create an online game using HTML forms and php. Where do we begin?
Back to top View user's profile Send private message
whackaxe
-


Joined: 28 Jun 2003
Posts: 90

PostPosted: Fri Jan 02, 2004 4:08 am    Post subject: Reply with quote

replace $YourName with $_POST['your_name'] and $FavoriteColor with $_POST['FavoriteColor']

are you completly new to programming?

in any case you should go here for tips and scripts
www.hotscripts.com
and here for more detailed help
www.codingforums.com
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 4:16 am    Post subject: yea Reply with quote

Yea, I am in fact new to programming. I only know HTML. I took a class on that when I was in school. But then again, HTML is VERY easy and anything beyond that is unknown to me. I do want to get into it tho.
Back to top View user's profile Send private message
whackaxe
-


Joined: 28 Jun 2003
Posts: 90

PostPosted: Fri Jan 02, 2004 4:19 am    Post subject: Reply with quote

gd gd. enjoy the ride then. im way to tired now, but next time im on the forums, ill pm you some good begginers tutorials :)
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 4:26 am    Post subject: hmmm Reply with quote

I replaced $yourname with $_POST['your_name'] and $favoritcolor with $_POST['favoritecolor'] and it still does not work. Any suggestions?
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 4:27 am    Post subject: This is what the php code looks like Reply with quote

This is what my php code looks like now

<html>
<head>
<title>Test!</title>

</head>

<body bgcolor="#FFFFFF" text="#000000">

<p>
Hi <?php print $_POST['your_name']; ?>

<p>
You like the Color <b> <?php print $_POST['FavoriteColor']; ?> !?! </b>

<p>You oughta be ashamed of yourself!

</body>
</html>
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 4:36 am    Post subject: HTML file Reply with quote

My HTML file looks like this


<html>
<head>
<title>My Form</title>
</head>
<body>

<form action="color.php" method=post>

My name is:
<br> <input type="text" name="YourName">

<p> My favorite color is:
<br> <input type="text" name="FavoritColor">
<p>

<input type="submit" name="submit" value="Enter My Data!">
</form>

</body>
</html>


Something does not match up, because either this code or the other code I had before work. What is wrong?
Back to top View user's profile Send private message
Moxxnixx
-


Joined: 21 Jun 2003
Posts: 1226
Location: Florida

PostPosted: Fri Jan 02, 2004 4:58 am    Post subject: Reply with quote

Use this:
Code:
<html>
<head>
<title>Test!</title>

</head>

<body bgcolor="#FFFFFF" text="#000000">

<p>
Hi <?php print $_POST[YourName]; ?>

<p>
You like the word <b> <?php print $_POST[FavoriteColor]; ?> !?! </b>

<p>You oughta be ashamed of yourself!

</body>
</html>

You didn't need the single-quotations for YourName and FavoriteColor.
Also got rid of the underscore in YourName.

In the future, always make sure your values match each other.
YourName and Your_Name do not match.

Also, check uppercasing and lowercasing.
YourName and yourname do not match.
Back to top View user's profile Send private message Visit poster's website
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 5:48 am    Post subject: Thanks Reply with quote

Thanks Ill give it a try
Back to top View user's profile Send private message
Vapor
-


Joined: 01 Jan 2004
Posts: 35

PostPosted: Fri Jan 02, 2004 5:57 am    Post subject: IT WORKS! HAHA Reply with quote

Thanks! That works
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Jan 02, 2004 5:57 pm    Post subject: Reply with quote

I have ran into problems using the $_POST[''] to register a varible
in PHP , if you want to be sure that every varible works with PHP , use

$_REQUEST[varible]

I use this for my Virtual Hosts program inspired
by the forum user Bluedog http://www.multiple-sites.tk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group