php code not executing instead just showing on page screen [duplicate] - php

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
i am trying to execute my php code, instead it just blows it back at my screen. page should be black to execute the code at the background.
I've let other poeple use this same code worked for them.

After setting xampp on your local pc, you've created a local server with apache, mysql, php stack. So when you write any php code, you need to execute/interpret it through your local server.
For example you need to use localhost/phpmailer_test/index.php not file:///C:/xampp/htdocs/phpmailer_test/index.php. If it was a .html file then you can use the file path to execute it but for server side language like php, python and so called server side languages you've to execute your code base through a server.

Seems like you are accessing your file through the file system, which means you are using your browser as something like a text editor. In order to have the php file executed on opening there are several things that you must do:
Set up a server on your computer that can execute PHP. (MAMP or XAMPP are easy to install)
Change the permissions of your server so that you can access it through localhost or 127.0.0.1.
Set up the file system of your server so that you can find your PHP file.
In your case you are using XAMPP, so the htdocs folder should be the 'root' of your local server, then you will be able to access any folder within there by entering the path after htdocs. In your case it should be localhost/phpmailer test/index.php.

Related

PHP file not loading in WAMP localhost [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am new to php and utilizing WAMP platform (version 3.0.6). I have two php files, one is a database connection script to the MySQL databse I created, the other is an html web form with embedded php scripts. Both were created in Microsoft Notepad as my editor and saved with the extension (.php) in the Windows(C:) >wamp64 >www >demoproject folder. While browsing in Windows explorer I noticed the file type is saved as "Text Document", even though the extensions were both saved with .php.
When I launch localhost in my browser and select the project folder listed under Your Projects I receive an error "This site can't be reached". Not sure why this is happening. I am able to open the root directory if I navigate to localhost/demoproject , which from there I can see the two php files (saved as Newspaper2.html.txt and connect-mysql.php.txt). When I launch the newspaper file (html form with php) all I receive is the scripting I created, as opposed to opening the web form. I checked the port for the localhost and I am running on port 80, and I've tried playing with the file extensions a little but it hasn't helped. Apologies if this has been asked before, I didn't see anything specific to this issue. I appreciate any assistance! Thanks.
Files that don't end in .php will not be interpreted unless you have configured their extension to be interpreted in your php.ini.
Basically: remove the .txt from the end.

PHP echo: can't reproduce W3school's code [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
I just started learning php and this is what I have done:
I copied the code from the left panel on this page and pasted them into a local html file. But when I open the html in browsers (firefox and chrome), the page doesn't look like what it should be: There is no format and the word 'echo' and some symbols are shown on the page. Why does this happen? How can I fix this issue?
PHP is a serverside scripting language. It has to be interpreted by a PHP interpreter that is in some way connected or integrated into an HTTP (web) server. There are a number of different ways to do that, with varying degrees of complexity.
How and where you setup your php + webserver is up to you, and the ways to do that typically start with the operating system you are running your workstation on, assuming you want to do so, locally.
You can go right to here for a jumpstart: http://www.phptherightway.com/#getting_started
The extension for a page that has php codes must be .php and not .html. Also, for the PHP code to execute you must be running Apache server on your machine.
This is a good tutorial for beginners, which tells you how to run PHP codes.
The steps are as follows
Open any Text Editor. Install new if you don't already have any good Text Editor installed. (My Favorite is Sublime Text & Notepad++)
Write the following PHP Program / CODE in the Text Editor: '; ?> This is
test.php File.
Save the file in XAMPP Installation Directory \ Web Root Directory Note-1: Default XAMPP Installation Directory in Windows is C:\xampp
Note-2: Default Web Root Directory in XAMPP is htdocs. All your php
files will have to be in this htdocs folder. That means, for a typical
installation of XAMPP in Windows, you will have to save the PHP CODE
in C:\xampp\htdocs folder.
When you save the file, name it test.php (just as an example, any valid file name with .php in the end will work). Note: when you save
this file, make sure it has no .txt extension at the end. Some text
editors place .txt at the end of file name, so it becomes test.php.txt
instead of test.php. To avoid this, when you save the file using any
text editor, place double quote around the file name: e.g. "test.php"
Then, go to XAMPP installation folder (typically, C:\xampp) and run xampp-control.exe by double clicking it.
In the xampp-control window, click the start button beside Apache. Later, if you need other options like MySQL, you'll also have to start
MySQL by clicking the start button beside MySQL in the XAMPP control
Panel. Note: if your OS hides common file extensions, then you'll see
xampp-control, instead of xampp-control.exe
Now, in your web browser's address bar, type the address: http://localhost/test.php

Code shown as text output

I'm a newbie to Facebook app development. It almost works when the page liked.php is shown (it's shown when a user liked the site), the PHP code is displayed as text output.
my liked.php code:
deleted for privacy reasons
?>
Here's the output(it's shown as blank text):
I simply don't know why. Even the error_reporting(E_ALL); doesn't show anything. Simply blank text output. I use the newest facebook php sdk.
I guess the problem is not in the code but in the configuration of your server. You need to tell the server to execute the php code instead of displaying it.
Sounds like you either don't have PHP installed or you're not using a file extension which invokes the PHP engine - is your file called [Blah].php?
Some things to check:
You're serving the file from a web server (not locally)
The server has PHP installed
Your webserver is configured to use the PHP engine to handle the file type you're using (usually .php or .php4 or similar)
creating a new file with just <?php phpinfo(); ?> and serving it should give you lots of info about your PHP install.
If you have access to the server, you should be able to run PHP from the command line/shell

Can we acces a file in C or D drive or any out side drive from a html/php program file in in wamp webserver(localhost server)?

I have a simple html program. It has a link, targeted to a pdf file.
Please see the program here
filename : invoice.html
My invoice
Here when I click on the link, pdf file will be open. Working well.
Then I called the same file from my localhost wamp server.
http://localhost/invoice.html.
But When I call the same program from my localhost, my link is not working!!!
Can you explain me why it is not working or how I can activate the link. Is there any option in Apache server or php settings ?
What's an "out side drive"?
I have a simple html program
HTML is not a programming language - its a data construct / declaration.
Here when I click on the link...Working well....http://localhost/invoice.html...not working
Does that mean that it works when you load the HTML file directly from your filesystem?
why it is not working or how I can activate the link
Certainly it has got nothing to do with Perl, PHP, Apache nor WAMP (the tags on your post). The problem is on your browser.
Is there any option in Apache server or php settings ?
No - because the problem is strictly client side.
I assume that the target file exists on the machine where you are running the browser.
It would have helped if you'd said which browsers you had tested this with. I would have expected it to have worked. Did you get an error message?
did you check if apache server is running on localhost? try to stop and restart the server and check if it works.
The link points to the C:\invoice.pdf on the client side. I wonder if this is what you want. It's more likely that you setup another Directory and alias in httpd.conf which points to C:\, then change the link accordingly.

I have a problem with my php script

I have a form where it request name,email,zipcode. However the problem is that. when you click on submit. it ask you to open the file it doesn't go to the script.
The website is http://childcarelv.org/newsletter.html
PHP isn't being handled by your server. Instead, it is just being output straight to the browser.
This is a server configuration issue.
Your server is configured with the correct MIME type (it is returning application/x-httpd-php), but isn't set up to actually use PHP to process it.
Since you are using Apache, read the configuration instructions here: http://www.php.net/manual/en/install.unix.apache2.php
Looks like you might be hosting with ipower.com. If that is the case, this is an issue for them to solve.
From your description it seems that server is not able to execute the php script, and thus gives it as download to the client.
You should try to put the following code in a file named testphp.php and place in your public home directory and go to the page to see if php extension is mapped to the php module on your server.
<?
phpinfo();
?>
This is just to verify/prove that there is nothing wrong in your script, and even a simple test script won't work.

Categories