Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: coopster & jatar k

PHP setup question

   
5:20 pm on Oct 22, 2002 (gmt 0)

10+ Year Member



I am just starting out with PHP. I installed PHP and mySQL in Windows today to work with IIS as a testing server. I got PHP working fine (it will pull dates from the server etc...) except when I try to send URL query strings to a PHP page. I think i might need to configure something else in php.ini or something.

Say i have a generic HTML form:

<form action="welcome.php" method="get">
First Name: <input type="text" name="firstname" /><br />
Last Name: <input type="text" name="lastname" /><br />
<input type="submit" value="Submit" />
</form>

Then on the php page I have:

<?php
echo( "Welcome, $firstname $lastname!" );
?>

It shows the querys in the url /welcome.php?firstname=*&lastname=*

But All I get is Welcome, ! on Submit.

Anyone have any ideas what I am doing wrong? Thanks.

5:23 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you can only use those types of vars to echo if you have register_globals on.

try this

echo( "Welcome, $HTTP_GET_VARS["firstname"] $HTTP_GET_VARS["lastname"]!" );

5:30 pm on Oct 22, 2002 (gmt 0)

10+ Year Member



Thanks for the reply.
That gave me this error:

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\inetpub\wwwroot\welcome.php on line 7
I even tried it like this:
echo( "Welcome to our Web site, " . $firstname . $lastname . "!" );
Didn't work either.

Also, register_globals = On in my php.ini.

[edited by: RussellC at 5:34 pm (utc) on Oct. 22, 2002]

5:33 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



what version of php is it?
5:34 pm on Oct 22, 2002 (gmt 0)

10+ Year Member



PHP 4.2.3
5:36 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



try this

echo "Welcome, " . $_GET["firstname"] . " " . $_GET["lastname"] . "!";

<added>missed a dot, sorry

5:39 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try

echo( "Welcome, {$HTTP_GET_VARS['firstname']} {$HTTP_GET_VARS['lastname']}!" );

The {} lets PHP know to interpolate the array reference correctly. using "'" instead of '"' for the array key string avoids any possibility of your string being interpretted as ending at the '['.

If you're using a recent version of PHP, you might want to use $_GET instead of $HTTP_GET_VARS. $HTTP_GET_VARS is deprecated and may be removed in the future.

<added>Jatar_k's last approach ought to work, too.</added>

[edited by: dingman at 5:41 pm (utc) on Oct. 22, 2002]

5:40 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I donīt mind which version you are running ;)

Try this

echo( "Welcome, $_GET[firstname] $_GET[lastname]!" );

I do actually. And I am slow.

Andreas

5:42 pm on Oct 22, 2002 (gmt 0)

10+ Year Member



That gave me:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in c:\inetpub\wwwroot\welcome.php on line 7

Bingo:
I just make a phpinfo.php file to look at the settings on my php.ini file and it looks like all of the stuff I changed in php.ini didnt really change. It says register_globals = Off and it shows my extensions directory as c:\php4 when it isn't. I have the php.ini file in C:\windows\. Why isnt it seeing my settings changes?

5:47 pm on Oct 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you restarted the web server? I don't know about Windows and IIS, but you have to restart Apache after making changes to php.ini.
5:51 pm on Oct 22, 2002 (gmt 0)

10+ Year Member



I took a new php.ini and edited re-edited it and stuck it back in c:\windows and then restarted to web server and now it works! The old php.ini must have gotten messed up or corrupted or something. Thanks for the help everyone! I love this forum.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month