File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes PHP and the fly likes First script for PHP is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "First script for PHP is not working" Watch "First script for PHP is not working" New topic

First script for PHP is not working

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 363
I have following file phpTest.html

Another file on server is phpTest1.php in the same location where phpTest.html is
When I feed data in two text fields in phpTest.html form and click submit, I dont get message from phpTest1.php. Instead of that, I get message "Do you want to open or save phpTest1.php(299 bytes) from My-PC ?"
When I click on open it opens source file phpTest1.php from server instead of displaying message. Why is that ?

How can I get message displayed from php script ? Apache server is running and WAMP is server is started (Apache MySQL, PHP for windows).

Tim Moores

Joined: Sep 21, 2011
Posts: 2408
Sounds like PHP is not configured correctly - instead of it being execute don the server the Apache server apparently serves it to the client. Check the PHP installation documentation to see if everything concerning mod_php is set up correctly.
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

Check the httpd.conf file and make sure you have lines that look like this (your paths might be different):

The second line enables PHP within Apache. The third line tells Apache to let PHP handle all requests for files ending in .php

By the way, I usually use a simple phpinfo file to test PHP:

I call it info.php and use http://localhost/info.php to access it. I get all kinds of data on my PHP setup if everything is correctly configured..
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 363
Thanks for replies. But none of the suggestion is working.

Now I have put phpTest1.php file in root dir (www) instead of putting in dir where phpTest.html is placed. Then I changed phpTest.html as follows
Now when I type in fields and click on submit phpTest.html, I am getting response from phpTest1.php

But I don't think this is right way to do things. Please let me know whats wrong I am doing and suggest correct approach.

Secondly, I am using following code with phpTest1.php script When I use this code, message is not getting sent to and I get following message.
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\phpTest1.php on line 12

Why is that ? I dont unerstand this message.How can I use mail() in the script ?
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

Please don't side-track your main question with an email question. Setting up email under PHP is a whole different topic. If you want to discuss that, please delete the email question from this post and crate a new discussion thread with that question.

Please read: ItDoesntWorkIsUseless
I pointed out some configuration settings you should have. If they are not working for you, then you need to post the settings that you have; there must be something wrong with them but without seing what you have I can't help you. Please post your httpd.conf file.

The "action" value in the <form> is not what you want. This limits your app to running only on your PC. You really want to have it the way it originally was.

Also, please give full directory paths. I have no idea where "www" is located (I would know on Linux, but you're running Windows). Give the full paths for both the HTML and PHP file.
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 363
following is path for httpd.conf and below that is httpd.conf file

following is path for www root dir

Following is path for firstTest.html parent dir
"C:\Users\Nirjari\Desktop\all text files\HTML Files"

I have placed one copy of phpTest1.php in this location and in www root dir.

Both mail() is part of first script and thats why I asked question about it in here.

Please let me know why is this script not working.

Thanks for your support
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

Following is path for firstTest.html parent dir
"C:\Users\Nirjari\Desktop\all text files\HTML Files

This explains a lot. How did you open the HTML file? By double-clicking on it in Explorer? That is not how things work. Instead, you should have something like this:


Then you need to go to your browser and enter this url: http://localhost/app/phpTest.html

Then it should work.

By the way, the "app" in the path and URL is really not necessary, but it helps if you want to have multiple apps running. And you can replace "app" with anything your like.

And you really need to start another thread for the email!!! (Even though you are calling mail() in the same script, dealing with mail is a whole separate issue.)
It is sorta covered in the JavaRanch Style Guide.
subject: First script for PHP is not working
Similar Threads
recod is not inserting in mysql databse
Using javascript with PHP
Javascript and PHP
geting focus on radio button
Writing to web space from Java applet.