View previous topic :: View next topic |
Author |
Message |
peok -
Joined: 16 Jun 2003 Posts: 6
|
Posted: Sat Jul 10, 2004 5:37 am Post subject: php, forms, and variables |
|
|
I'm still just a few days into learning php, and I've been going though this tutorial:
Tutorial, Page 6
Anyway, it's supposed to take some input from an html form, and slap it into a page with php. Well obviously I'm running abyss, and I get php error messages, basically saying the variables I'm trying to echo/print are not defined. I switched the method to "get" so that the info was in the url, but that didn't work.
I found this link http://os17fan.cjb.net/web/php_tutorial.html in these forums, and changed "register_globals" to on in the php.ini file, but that didn't do it. Um, what does the "register_globals" do anyway, the .ini file was a bit cryptic for me. Anyway, so any ideas on why it's not picking up the variables or whatever?
thanks |
|
Back to top |
|
 |
niteowl -
Joined: 30 Jun 2004 Posts: 3
|
Posted: Sat Jul 10, 2004 3:39 pm Post subject: this may help |
|
|
See if the following works,
In the bad_words.php file replace the variable name, $variablename, by $_POST['variablename'] if you are using the POST method for submitting the form. Otherwise, use $_GET['variablename'], if you are using the GET method.
For example, replace $yourname in the php file by $_POST['yourname'].
This has to do with the later php version has diabled the Global registration by deault. _________________ niteowl
----------------------------------------
PowerMac G4 | 400Mz | 640M RAM | OS X.3.4
PowerBook G4 | 12" 800Mz | 640M RAM | OS X.3.4
iPod 10MB |
|
Back to top |
 |
 |
peok -
Joined: 16 Jun 2003 Posts: 6
|
Posted: Sat Jul 10, 2004 4:09 pm Post subject: |
|
|
Ok, tried it but I just got a slightly modified error message.
First setup was:
Code: | <html>
<head>
<title>My Form</title>
</head>
<body>
<form action="bad_words.php" method="post">
My name is:
<br><input type="text" name="YourName">
<p>My Favorite Dirty Word is:
<br><input type="text" name="FavoriteWord">
<p>
<input type="submit" name="submit" value="Enter My Data!">
</form>
</body>
</html> |
and
Code: | <html>
<head>
<title>Perv!</title>
</head>
<body>
<p>
Hi
<?php echo $YourName ?>
<p>
You like the word <b> <?php print $FavoriteWord; ?> !?! </b>
<p> You oughta be ashamed of yourself!
</body>
</html> |
which returned
Code: | Hi
Notice: Undefined variable: YourName in D:\website\favwords\bad_words.php on line 8
You like the word
Notice: Undefined variable: FavoriteWord in D:\website\favwords\bad_words.php on line 10
!?!
You oughta be ashamed of yourself! |
if i change bad_words.php to
Code: | <html>
<head>
<title>Perv!</title>
</head>
<body>
<p>
Hi
<?php echo $_POST[YourName]; ?>
<p>
You like the word <b> <?php print $_POST[FavoriteWord]; ?> !?! </b>
<p> You oughta be ashamed of yourself!
</body>
</html> |
then I get
Code: | Hi
Notice: Use of undefined constant YourName - assumed 'YourName' in D:\website\favwords\bad_words.php on line 8
myname
You like the word
Notice: Use of undefined constant FavoriteWord - assumed 'FavoriteWord' in D:\website\favwords\bad_words.php on line 10
ooga !?!
You oughta be ashamed of yourself! |
Any ideas? In php.ini I have
Code: | ; Whether or not to register the EGPCS variables as global variables. You may
; want to turn this off if you don't want to clutter your scripts' global scope
; with user data. This makes most sense when coupled with track_vars - in which
; case you can access all of the GPC variables through the $HTTP_*_VARS[],
; variables.
;
; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = On |
(used to be "Off")
Thanks a lot for your response niteowl
Last edited by peok on Tue Jul 13, 2004 10:04 pm; edited 1 time in total |
|
Back to top |
|
 |
niteowl -
Joined: 30 Jun 2004 Posts: 3
|
Posted: Sat Jul 10, 2004 5:18 pm Post subject: |
|
|
hey,
Looks like you have missed out the quotation marks before and after the variable names - for example, it should be $_POST['yourname'] rather than $_POST[yourname] and it should be $_POST['favoriteoword'] rather than $_POST[favoriteword].
Hope that fixes the problem. _________________ niteowl
----------------------------------------
PowerMac G4 | 400Mz | 640M RAM | OS X.3.4
PowerBook G4 | 12" 800Mz | 640M RAM | OS X.3.4
iPod 10MB |
|
Back to top |
 |
 |
peok -
Joined: 16 Jun 2003 Posts: 6
|
Posted: Sat Jul 10, 2004 5:29 pm Post subject: |
|
|
It Worked! Yay! Thanks so much niteowl
um, so the is the reason the tutorial didn't work because its a bit depreciated and i need the $_GET[] or $_POST[]?
Thanks so much, once again. I'm ready to get working now I think. |
|
Back to top |
|
 |
niteowl -
Joined: 30 Jun 2004 Posts: 3
|
Posted: Sat Jul 10, 2004 7:39 pm Post subject: |
|
|
hey peok,
No problem. After all this is what the forum is partially for.
The code in the tutorial would work if register_globals is on, which was the default in the earlier version of php. the $_POST[] method would work, however, regardless of whether register_globals is enable or not - at least that was my understanding.
Happy coding..... _________________ niteowl
----------------------------------------
PowerMac G4 | 400Mz | 640M RAM | OS X.3.4
PowerBook G4 | 12" 800Mz | 640M RAM | OS X.3.4
iPod 10MB |
|
Back to top |
 |
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sun Jul 11, 2004 7:30 pm Post subject: |
|
|
peok wrote: | um, so the is the reason the tutorial didn't work because its a bit depreciated and i need the $_GET[] or $_POST[]?
|
If variables can come from a GET or a POST and if you don't want to bother yourself with such a detail, use $_REQUEST[] instead. It will give you the variable value whether it comes from a GET or a POST request. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
 |
00squeaky -
Joined: 11 May 2004 Posts: 60
|
Posted: Mon Jul 12, 2004 10:40 pm Post subject: |
|
|
ick.
just download the php manual off of the php site.
okay, say you have an input in your form like this:
<input name="uname" value="">
when you execute the script, make sure it is $HTTP_POST_VARS['uname'];. also, make sure your php script is on a separate page.
also, there really were not any errors, it was jst telling you an assumption ;) _________________ Languages mastered:
HTML,GML,C,PHP,MYSQL (not really a language, but wtf) |
|
Back to top |
|
 |
|
|
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
|
|