LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2010, 11:56 AM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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>
 
Old 04-28-2010, 12:40 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
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.
 
Old 04-28-2010, 12:41 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
And what do Apache logs say ?
 
Old 04-28-2010, 01:34 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
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 ?
 
Old 04-28-2010, 03:22 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Sergei Steshenko View Post
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 View Post
And what do Apache logs say ?
Don't know where that is.

Quote:
Originally Posted by Sergei Steshenko View Post
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
 
Old 04-28-2010, 03:24 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
...
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 ?
 
Old 04-28-2010, 03:28 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
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 ?
 
Old 04-28-2010, 03:32 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
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.
 
Old 04-28-2010, 03:45 PM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
What is it between you two?
 
Old 04-28-2010, 04:53 PM   #10
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 04-28-2010 at 05:01 PM.
 
Old 04-28-2010, 05:01 PM   #11
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by paulsm4 View Post
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!
 
Old 04-28-2010, 05:06 PM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by paulsm4 View Post
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.
 
Old 04-28-2010, 05:19 PM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by smeezekitty View Post
What is it between you two?
His answers are very cryptic and condescending.
 
Old 04-28-2010, 05:27 PM   #14
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
His answers are very cryptic and condescending.
What exactly you do not understand ?
 
Old 04-28-2010, 07:28 PM   #15
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Suse 9.3/apache2/php4 - Firefox tries to download index.php, other *php pages work stefanlasiewski SUSE / openSUSE 1 01-18-2006 06:12 PM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 06:51 AM
Getting PHP to work..... wacki Programming 4 08-24-2005 05:38 PM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 11:05 AM
getting PHP to work...please help! rudini Linux - Software 12 03-24-2005 05:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration