Page 1 of 1

need help with apache, mysql, php set-up

Posted: Sat Jan 03, 2004 7:53 pm
by geff_chang
need help with apache, mysql, php set-up

just recently i made a WAMP (windows, apache, mysql, php) set-up, and everything went smoothly (following all instructions). i tried viewing:

Code: Select all

<?php
	echo 'PHP is working.<br>';
	echo phpinfo();
?>
and it worked just fine.

but when i tried (who_are_you.php):

Code: Select all

<html>
<head>
     <title>Who Are You?</title>
</head>
<body>
<form action="you_are.php">
     Please enter your name:<br> I am.
     <?php
          print('<input type="text" name="person" value="' . $person . '"size="15">');
     ?>
     <input type="submit" value="Go!" size="15">
</form>
</body>
</html>
and (you_are.php):

Code: Select all

<html>
<head>
     <title>You Are!</title>
</head>
<body>
<?php
     print('Well, hello ' . $person . ', nice to meet you!');
     print('<br>');
     print('<a href="who_are_you.php?person=' . urlencode($person) . '">Back to Who Are You?</a>');
?>
</body>
</html>
the page loads, but the value for $person does not appear. for example, i put in geff_chang in the box, you_are.php only gives me "Well, hello , nice to meet you!" instead of the expected "Well, hello geff_chang, nice to meet you!"

am i missing something? maybe it has something to do with security issues? service packs i have installed? i have already deleted my hosts file (which by the way blocked localhost), but have not gotten what i want. i hope somebody can help me, because i need to start learning PHP for my web dev class. (and my classmates don't even know a thing about it yet. and forget the teacher, he's a loser). i'm better off with you guys here.

FYI, i also have sygate personal firewall pro and norton antivirus. BUT, that doesn't affect anything, does it?

Posted: Sat Jan 03, 2004 8:11 pm
by Paddy
Your first site does not need any php.

Code: Select all

&lt;html&gt;
&lt;head&gt;
     &lt;title&gt;Who Are You?&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="you_are.php" method="post"&gt;
     Please enter your name:&lt;br&gt; I am.
     &lt;input type="text" name="person" size="15"&gt;
     &lt;input type="submit" value="Go!" size="15"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
When you catch the value in the form that is when you need php. Also not e how to get the variable. If your host has golbal variables turned off then you will need the top part of the code. Good coding practice anyway.

Code: Select all

<?php
$person  = (isset($_POST['person'])?$_POST['person']:"");
?>
<html>
<head>
     <title>You Are!</title>
</head>
<body>
<?php
     print('Well, hello ' . $person . ', nice to meet you!');
     print('<br>');
     print('<a href="who_are_you.php?person=' . urlencode($person) . '">Back to Who Are You?</a>');
?>
</body>
</html>
That should work. Hope it helped.

Posted: Sat Jan 03, 2004 9:04 pm
by DuFF
Paddy wrote:

Code: Select all

<?php
$person  = (isset($_POST['person'])?$_POST['person']:"");
?>
Because you are passing the variables through the URL, you will need to use $_GET instead of $_POST.
:wink:

Posted: Sat Jan 03, 2004 9:17 pm
by Paddy
Didn't see that. You will need it in who_you_are but not in you_are. you_are still uses post. I believe I was right there Duff. ;)

Posted: Sat Jan 03, 2004 9:34 pm
by geff_chang
thanks a lot. i tried it, and it worked. the codes i put in earlier were found in a book i bought called Mastering PHP 4.1 by Allen and Hornberger (SYBEX) - cover price of USD49.99 (bought here for PHP 1599). i can't believe i spent money on stuff that doesn't work. grr.

i thought i had to reinstall apps again.

Posted: Sat Jan 03, 2004 9:48 pm
by geff_chang
clicking on the link generated by (after submitting stuffs in who_are_you.php):

Code: Select all

print('<a href="who_are_you.php?person=' . urlencode($person) . '">Back to Who Are You?</a>');
gives me:

Code: Select all

Forbidden
You don't have permission to access /"who_are_you.php on this server.

Posted: Sat Jan 03, 2004 10:08 pm
by Paddy
geff_chang wrote:thanks a lot. i tried it, and it worked. the codes i put in earlier were found in a book i bought called Mastering PHP 4.1 by Allen and Hornberger (SYBEX) - cover price of USD49.99 (bought here for PHP 1599). i can't believe i spent money on stuff that doesn't work. grr.

i thought i had to reinstall apps again.
As I said, your server probably has global variables turned off. This is a relatively recent change to php. I am sure the rest of the book will server you well.

As for your other problem I am not sure why it does that. Does the URL that the second page created look correct?

Posted: Sat Jan 03, 2004 10:29 pm
by geff_chang
no, it doesn't. but i chaneged \s to /s. and it worked well. then, NO. this is stoopid. anyway, how do i turn global vraiables on?

Global variable:

Posted: Sun Jan 04, 2004 1:19 am
by juzatestdrive
geff_chang wrote:
no, it doesn't. but i chaneged \s to /s. and it worked well. then, NO. this is stoopid. anyway, how do i turn global vraiables on?
I did this to turn the global variables On:

(1) Search for the file php.ini at:
C:\Winnt\ (if using WinNT/2000/XP)
OR
C:\Windows\ (if using Win95/98/Me)

(2) Double click php.ini to edit.

(3) Search for the following line:

; 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 = Off

Change it to:
register_globals = On

Hope it works!