/index.php no output

Hi,
Thanks ahead of time. I think I found the right place to get my head straightened out by finding this forum.
I am not new to programming in general but i am new to php.

Problem.
When I type the following in the URL - the screen remains blank.

localhost/phpWithAlex/index.php

Background:
I am on a Mac. OS X 10.8. MountainLion.
I am using NETBEANS for my editor…

I enabled apache.
Within my httpd.conf file I uncommented one line - a load module as described in severals AMP setups.
From terminal i started apachectl and verified it is running.

Before doing any install, I cross-referenced to make certain that I was doing it right.
I downloaded phpMyAdmin.
from localhost/phpMyAdmin I logged on.

My approach:
I am doing a tutorial sequence that are videos by a guy named Alex.
They are very good. I went thru the entire sequence just listening and now I am coding or trying to do it with him.

But
Alex is using xampp on Windows.
Alex has a path such as this…
xampp > htdocs > series

WhereAs my path is…
Library > WebServer >Documents > phpWithAlex

‘Series’ is the folder where Alex is putting all the tutorial .php files.
'phpWithAlex is the folder I am putting all the files I am creating.

We created our first file called index.php.
Used the ‘hello world’ code.
[php]<?php
Echo ‘hello world’;
?>
[/php]
I refresh my screen localhost/phpWithAlex/
Yes there is Output Hello World on the screen.

Then we added this code.
[php]<?php
$name = ‘Alex’;
$age = 21;
if (strtolower($name)===‘alex’){
if($age>=21) {
echo ‘You\re over 21’;
if (1===1){
echo ‘Yes, 1 is equal to 1’;
}
}
}else {
echo ‘you’re not alex’;
}
?>[/php]
NO OUTPUT

I checked from the finder. The index.php is in the phpWithAlex folder; path Library/WebServer/Documents/phpWithAlex/index.php

Why would it work for the ‘hello world’ script but not now.
I am doing what he is doing and I check by code carefully.

thanks.

You are missing a couple elses if you change the variables around which is why there is no output. See the changes below.

[php] <?php
$name = ‘Alex’;
$age = 21;
if (strtolower($name) === ‘alex’)
{
if ($age >= 21)
{
echo ‘You\re over 21’;
if (1 === 0)
{
echo ‘Yes, 1 is equal to 1’;
}
else
{
echo ‘Not equal to one’;
}
}
else
{
echo ‘Not 21’;
}
}
else
{
echo ‘you’re not alex’;
}
?>[/php]

[size=12pt]Thank you.

That worked.[/size]

If possible can you change the subject of the post to be exactly descriptive. Thanks
SUBJECT:On a Mac: fopen( ) does not create a file or accept data. change permissions. chmod.

[size=12pt][size=14pt]Thank you to those who responded.[/size][/size]
After a crazy amount of troubleshooting and getting hints and feedback from others, I was so darn determined to get on with my tutorials and I found the solution myself.

Keyword search: php and ‘Mac computer’ and fopen and chmod.
Using:php and Mac and fopen() didn’t get me there.

I hope this forum allow for URL insertion. Others do.

[size=12pt]1. This is the solution that I used.
It was all about PERMISSIONS and I used the Mac Finder.[/size]

This is my DocumentRoot path: /Library/WebServer/Documents
This is the path to the directory where I am saving all of my example programs from tutorials:
/Library/WebServer/Documents/phpWithAlex

This was how I went about troubleshooting this just to make certain that I was [size=12pt][size=14pt]clear about at which level I needed to allow ‘read and write’ permissions. [/size][/size] I should have started from php/WithAlex but I started on the top.

From the Mac Finder I navigated to Library and changed permissions to ‘read and write’ at all 3 levels:
System
Wheel
Everyone.
From the Mac Finder I navigated to WebServer and changed permissions to ‘read and write’ at all 3 levels:
System
Wheel
Everyone.
From the Mac Finder I navigated to Documents and changed permissions to ‘read and write’ at all 3 levels:
System
Wheel
Everyone.

I kept running the code which uses the fopen() function each time to see if I was able to create a new file and that this file ACCEPTED DATA input from my form.

The code which is in the previous post, DID INDEED CREATE the file when I used FOPEN() once I changed permissions to ‘read and write’ for all levels on phpWithAlex.

Then I worked for the bottom back up the tree and reset permissions to just ‘read’ etc. etc.
I wanted to find out the least amount of permissions required to run the code.
The only folder that requires permissions set to ‘read and write’ for all 3 levels: system, wheel, everyone Was phpWithAlex.

  1. I like to work at the command line.
    You can use terminal on a Mac and set permissions using the chmod() function. Here is the link… Which explains many things and also why you may or may not want certain permissions at different levels.

If you read the last post, you will notice that I also modified my phi.ini and I ; un-commented a line
to find out if this allowed fopen() to work. It did not.
Then i set the ;comment =On rather than = Off etc. etc. it still did not allow fopen to work.
I am on a tablet or I would just copy paste those lines of code here.
If I leave this page and go to another and come back, this entire post disappears.
I learned that the hard way and had to start the post all over again.
I actually was curious so I put the ;comment back and it did not reintroduce the obstacle that I started with,
that fopen() would NOT create the file.

I am posting this exact post on 5 other forums that I am now frequenting because it was very time consuming to find this resolution. Although, this exact problem was not resolved from these forums, [size=14pt]I LEARNED A TON FROM VERY HELPFUL PEOPLE WHO ARE JUST DONATING THERE TIME.[/size] IS THIS WHAT KEEPING THE INTERNET FREE IS ALL ABOUT ? Sure it is. Thank ALL of you.

NOTE: I navigated away from this post to copy the URL and I lost my entire post and had to start over.
Also, it is not easy to find my own posts once I logon- if they do NOT have new comments.
It is really helpful to have a PREVIEW option.

When developing you need to output errors, notices and warnings. Add this to the beginning of your script and PHP should output any errors instead of just displaying a blank page (which you get if PHP fails miserably)

[php]ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

Note: it should be added inside the <?php ?> tags. You also don’t really need a closing PHP tag at the end of the file (it’s actually not recommended)

Thanks Jim.
I will do that.
I was wondering why within the tutorials, warnings and fatal errors showed up in the lesson but not for me.
I will insert the code in my php programs… Beginning… End ???

But I thought that I could also set this up in httpd.conf or php.ini.
I thought I did but it doesn’t work for me.

You can in php.ini.

Sponsor our Newsletter | Privacy Policy | Terms of Service