LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP doesn't work (https://www.linuxquestions.org/questions/programming-9/php-doesnt-work-804790/)

MTK358 04-28-2010 11:56 AM

PHP doesn't work
 
I wanted to play around with PHP, so I set up Apache and got PHP to work with it.

Printing little hard-coded messages works, but when I try anything having to do with parameters, cookies, etc. I just gat a blank page.

For example, this just gets me a blank page. If I comment out the for loops, it at least prints the hardcoded messages:

Code:

<html>
<head>
</head>
<body>
<?php
        echo "<h1>Parameters</h1>";
        echo "<h2>GET</h2>";
        echo "<pre>";
        for ($value as $key => $_GET)
        {
                echo $key . ' = ' . $value;
        }
        echo "</pre>";
        echo "<h2>POST</h2>";
        echo "<pre>";
        for ($value as $key => $_POST)
        {
                echo $key . ' = ' . $value;
        }
        echo "</pre>";
?>
</body>
</html>


Sergei Steshenko 04-28-2010 12:40 PM

Quote:

Originally Posted by MTK358 (Post 3950827)
I wanted to play around with PHP, so I set up Apache and got PHP to work with it.

Printing little hard-coded messages works, but when I try anything having to do with parameters, cookies, etc. I just gat a blank page.

For example, this just gets me a blank page. If I comment out the for loops, it at least prints the hardcoded messages:

Code:

<html>
<head>
</head>
<body>
<?php
        echo "<h1>Parameters</h1>";
        echo "<h2>GET</h2>";
        echo "<pre>";
        for ($value as $key => $_GET)
        {
                echo $key . ' = ' . $value;
        }
        echo "</pre>";
        echo "<h2>POST</h2>";
        echo "<pre>";
        for ($value as $key => $_POST)
        {
                echo $key . ' = ' . $value;
        }
        echo "</pre>";
?>
</body>
</html>


First try to replace $_GET with something has known hard-coded value.

Sergei Steshenko 04-28-2010 12:41 PM

And what do Apache logs say ?

Sergei Steshenko 04-28-2010 01:34 PM

Now the main "standard" question: what did you exactly read on PHP $_GET ? I.e. based on what exactly documentation/tutorial/example you think your code should work ?

MTK358 04-28-2010 03:22 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3950875)
First try to replace $_GET with something has known hard-coded value.

Didn't help:

Code:

echo "<h1>Parameters</h1>";
echo "<h2>GET</h2>";
echo "<pre>";
$values = array('key1' => 'value1', 'key2' => 'value2');
for ($value as $key => $values)
{
        echo $key . ' = ' . $value;
}
echo "</pre>";

Quote:

Originally Posted by Sergei Steshenko (Post 3950876)
And what do Apache logs say ?

Don't know where that is.

Quote:

Originally Posted by Sergei Steshenko (Post 3950927)
Now the main "standard" question: what did you exactly read on PHP $_GET ? I.e. based on what exactly documentation/tutorial/example you think your code should work ?

http://www.google.com/url?sa=t&sourc...Z7e8WrRYKRKBhg

Sergei Steshenko 04-28-2010 03:24 PM

Quote:

Originally Posted by MTK358 (Post 3951031)
...
Don't know where that is.
...

Just marvelous. You start a server and do not know where its log files are ? And how are you going to debug anything at all ?

Sergei Steshenko 04-28-2010 03:28 PM

Quote:

Originally Posted by MTK358 (Post 3951031)

OK, I've downloaded the PDF file. First of all, the name is alarming:

Quote:

Caffeinated Crash Course in PHP
.

Crash course means no serious insights.

Now, the course, of course, contains $_GET - on several pages. So based on which pages and what text did you write your code ?

Sergei Steshenko 04-28-2010 03:32 PM

The crash course you've chosen very poorly describes "the infrastructure" around $_GET.

I used Yahoo and

PHP $_GET tutorial

- this yields a number of matches, and they describe the mechanism much better.

smeezekitty 04-28-2010 03:45 PM

What is it between you two?

paulsm4 04-28-2010 04:53 PM

General PHP troubleshooting tips
 
Hi:

1. When in doubt, run phpinfo ():
Code:

<?php
  phpinfo ();
 ?>
  <= This should print out a whole bunch of info ... including your $_GET and $_POST variables (if you have any)

2. Start with the SIMPLEST HTML possible:
Code:

<html>
<head>
<title>this is a test</title>
</head>
<body>
<?php
  echo "<h2>Hello</h2>";
?>
</body>
</html>

3. Now try to access a PHP variable:
Code:

<html>
<head>
<title>this is a test</title>
</head>
<body>
<?php
  echo "<h2>_GET[greeting]: " . $_GET["greeting"] . "...</h2>";
?>
</body>
</html>

4. Try different URL arguments, for example:
5. Try more complex syntax

6. Rinse and repeat ;)

MTK358 04-28-2010 05:01 PM

Quote:

Originally Posted by paulsm4 (Post 3951110)
Now try to access a PHP variable:
Code:

<html>
<head>
<title>this is a test</title>
</head>
<body>
<?php
  echo "<h2>_GET[greeting]: " . $_GET["greeting"] . "...</h2>";
?>
</body>
</html>


Funny, that worked!

Sergei Steshenko 04-28-2010 05:06 PM

Quote:

Originally Posted by paulsm4 (Post 3951110)
Hi:

1. When in doubt, run phpinfo ():
Code:

<?php
  phpinfo ();
 ?>
  <= This should print out a whole bunch of info ... including your $_GET and $_POST variables (if you have any)

2. Start with the SIMPLEST HTML possible:
Code:

<html>
<head>
<title>this is a test</title>
</head>
<body>
<?php
  echo "<h2>Hello</h2>";
?>
</body>
</html>

3. Now try to access a PHP variable:
Code:

<html>
<head>
<title>this is a test</title>
</head>
<body>
<?php
  echo "<h2>_GET[greeting]: " . $_GET["greeting"] . "...</h2>";
?>
</body>
</html>

4. Try different URL arguments, for example:


5. Try more complex syntax

6. Rinse and repeat ;)

I am not sure the OP understands how data is passed back from browser to server. The tutorials I looked into give examples of such data passing.

MTK358 04-28-2010 05:19 PM

Quote:

Originally Posted by smeezekitty (Post 3951055)
What is it between you two?

His answers are very cryptic and condescending.

Sergei Steshenko 04-28-2010 05:27 PM

Quote:

Originally Posted by MTK358 (Post 3951141)
His answers are very cryptic and condescending.

What exactly you do not understand ?

graemef 04-28-2010 07:28 PM

Quickly looking at this the problem appears to be twofold:

First your looping syntax is wrong: I believe that it should be foreach ($ARRAY as $KEY => $VALUE)

Second you need to understand how to view the error messages that PHP generates. By default PHP doesn't display the error message on the screen but in a log file. You can change this characteristic by looking at the php configuration file php.ini, or you can look at the php log file where php specific errors are logged the path to the error log file is given in the apache configuration file

The default location for the ini file is /etc/php.ini but it could be different for your system.
The parts of the ini file that you need to locate is:
display_errors
log_errors
error_reporting

The default location for the apache configuration file is /etc/httpd/conf/hpptd.conf search for the term logfile, the default location will be /etc/httpd/logs/


All times are GMT -5. The time now is 03:07 PM.