***newbie alert***ranger***

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
Ranger
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Mar 04, 2003 12:01 pm

***newbie alert***ranger***

Postby Ranger » Tue Mar 04, 2003 12:28 pm

hi, all.

i'm running Windows XP Pro, IIS 5.0, PHP 4.2.3 as CGI. i used the installer from php.net to set up php up. i've been following bill mccarty's book php4: a beginner's guide without much trouble until i got to this part.

i have an html file called p-4-1.html with the following contents:

<html>
<head>
<title>Project 4-1</title>
</head>
<body>
<form method="post" action="p-4-1.php">
<h2>Contact List</h2>
Nickname:<br />
<input type="text" name="nickname"><br />
Full Name:<br />
<input type="text" name="fullname"><br />
Memo:<br />
<textarea name="memo" rows="4" cols="40" wrap="physical"></textarea>
<br /><br />
<input type="submit">
</form>

</body>
</html>

and i have the php file named p-4-1.php with this:

<?php
echo "<br>Nickname=$nickname";
echo "<br>Full Name=$fullname";
echo "<br>Memo=$memo";
?>

instead of getting what the books says i should, after entering some data:

Nickname=Charlie
Full Name=Charles
Memo=test

i get this:

Notice: Undefined variable: nickname in c:\inetpub\wwwroot\php-testing\p-4-1.php on line 2

Nickname=
Notice: Undefined variable: fullname in c:\inetpub\wwwroot\php-testing\p-4-1.php on line 3

Full Name=
Notice: Undefined variable: memo in c:\inetpub\wwwroot\php-testing\p-4-1.php on line 4

Memo=

i've spent a day checking to make sure i've written the code correctly. i'm certain that php and iis are working because i can get the phpinfo() to work and bring up all the information i need.

does anyone have any suggestions as to what to try next?

thanks,
ranger

Unknown
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Jan 13, 2003 10:33 am

Postby Unknown » Tue Mar 04, 2003 2:11 pm

$_POST['nickname'] instead of $nickname and so on.

edited by Redcircle 3-5-03

rich81
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Mar 04, 2003 3:45 pm

Postby rich81 » Tue Mar 04, 2003 6:51 pm

correct.

register_globals, which basically allows you to directly inherit form objects as variables in the script which is specified in <form action="">, from the page which contains the form, is switched OFF by default in newer versions of PHP.

using $_POST[varname] will allow you to access these variables.

not much of a change, but apparently good for security reasons i.e. not being able to override form variables with page.php?varname=newvalue etc.

if you want to store/modify variables for the whole session without having to pass them from page to page, look up session_start() and related info on php.net!

one more thing..... if you use functions in any of your includes and try to use $_post variables or session variables, the functions in the includes WILL NOT inherit the same variable scope, you have to pass the variables to the functions seperately.

User avatar
Ranger
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Mar 04, 2003 12:01 pm

help still needed!!!

Postby Ranger » Wed Mar 05, 2003 7:18 am

thanks for the help. i'm glad to know that the functionality had changed and it wasn't that i was misreading the book!

so, i changed my php file to look like this

<?php
echo "<br>Nickname=$_POST['nickname']";
echo "<br>Full Name=$_POST['fullname']";
echo "<br>Memo=$_POST['memo']";
?>

because i was told, quote, $_POST['nickname'] instead of $nickname and so on, unquote.

so when i send this through, i get the following error message:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\inetpub\wwwroot\php-testing\p-4-1.php on line 2

so now i need to ask where do i go from here?

thanks

sitting here waiting for the day when i can look back at this and laugh. :(

rich81
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Mar 04, 2003 3:45 pm

Postby rich81 » Wed Mar 05, 2003 2:54 pm

yeah i see whats wrong.

echo "<br>Nickame=$_POST['nickname']";

using that is a little bit dodgey because you're trying to sub in a value from an array index instead of just a plain variable.

assigning $_POST['whatever']" to a variable first fixes the problem. as tedious as it sounds, it's necessary if you just wanna sub the value straight into an echo or print().

So...

$nick=$_POST['nickname'];
echo "<br>Nickname=$nick";

...should work fine :)

User avatar
Ranger
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Mar 04, 2003 12:01 pm

thanks

Postby Ranger » Thu Mar 06, 2003 12:23 pm

yep, that did the trick, but what's more important, it makes sense.

thanks rich81!!

ranger :D


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests