+ 4

PHP not executing

Hallo, i have installed php with xampp and all the files are is a sub folder in C:\xampp\htdocs however when I try to submit a simple with 2 fields I get the php file as a html not as php. For some reason php is not executed. How can I fix this? The code: Html: <form method="post" action="db.php"> <input type="text" name="user">User <input type="text" name="pass">Pass <input type= "submit" value="send"> </form> Php NAME: <?php echo $_POST["user"]; ?> PASS: <?php echo $_POST["pass"]; ?> Thank you in advance!

24th Nov 2018, 10:55 PM
pap
pap - avatar
20 Answers
+ 7
I SOLVED IT!!! Here was the problem> Until now I just opened the HTML direct by clicking on the document. In the browser the URL locked like this: file:///C:/xampp/htdocs/DB/Log-In.html and as soon as I click the submit I get the php file, but opened from the browser and the URL locked like this: file:///C:/xampp/htdocs/DB/db.php I was clicking around and then I open test Folder (DB) but using the LOCALHOST this time then the URL was: http://localhost/db/Log-In.html And as soon as I submitted my form O! MIRACLE! IT WORKS!!!! But the URL of the WORKING PHP now was http://localhost/db/DB.php So, langer Rede kurzer Sinn: One must open the HTML files like WEB PAGES thorough the XAMPP Dashboard (LOCALHOST) and not as Files by simply clicking direct on them. Thank you girls and guys for your time, efforts an comments!!!
29th Nov 2018, 1:43 AM
pap
pap - avatar
+ 9
You mean all the other PHP files work, but just this one? well that's kinda odd. I had to mention the file extension issue because it was most related with PHP codes not executed, I'm glad you are aware of it : ) Have you tried to create another PHP file, and use it as the form's action attribute? if it works then delete the troublesome file and rename the new file as db.php to replace it. Waiting on you ...
26th Nov 2018, 2:25 PM
Ipang
+ 8
Just a guess, but are you sure that apache services are actually running? I don't know how it works with XAMPP but with WAMP i have to activate them manually each time i have to use my local web server.
25th Nov 2018, 12:19 AM
Maz
Maz - avatar
+ 7
I see you put the block between </head> and <body> try to move the blocks with PHP code into the document body, between <body> and </body>, and make sure you save the PHP file with .php file extension. If you use Windows, it is possible that the file is saved with different extension if the option for hiding file extension is enabled.
26th Nov 2018, 1:44 PM
Ipang
+ 5
I should've asked you in the first place, how you access your files, of course opening files that way wouldn't work, since by that it is not processed by PHP, you should treat the file like you would normally with files from an online website, only difference is the server address which is localhost : )
29th Nov 2018, 4:53 AM
Ipang
+ 4
pap I'm sorry to hear that. Actually for your case, since you haven't used SQL yet, it's OK *even if* MySQL isn't running, and since it is local server, you don't need internet connection to run the code. To test the installation, you simply surf to localhost on your browser, if you see error, then there's a problem, otherwise, we can assume it's OK. XAMPP normally shows a welcome page (IIRC), if you surf to localhost and see nothing (or see output of unprocessed text) it is possible installation was corrupt. Create a PHP file, save it as "info.php" in htdocs (not in subfolder), write this within the file; <html> <body> <?php phpinfo(); ?> </body> </html> Then surf to localhost/info.php in your browser, if you see PHP information as output, then your XAMPP installation is OK. Also remember, installation of software such as XAMPP requires administrative privileges, which without, *may* cause problem. Save copy of your code (HTML & PHP) and share it here so everyone can see clearly if there's a problem : )
28th Nov 2018, 9:08 AM
Ipang
+ 3
Maz , chuong , Akshay thanks you for your answers, but it is something else :( I checked - the Apache and MySQL work fine (green mark at xampp). Internet connection is also ok. the files are in the htdocs directory, but still i didn’t get the echoed valued, but the whole php file as an html exactlly as it is in the code with <?php...> and everything. the php is not executed. any suggestion?
26th Nov 2018, 9:05 AM
pap
pap - avatar
+ 3
Maz ,chuong , Akshay and here is my php code. maybe there is the problem... https://code.sololearn.com/w0UQFZ7H74Ud/?ref=app
26th Nov 2018, 1:21 PM
pap
pap - avatar
+ 3
Ipang thank you for your answer. the mistake is only at this code. In the original the <?php ... ?> are in the <body>. ai work with Notpad++ and the file is saved correct as php... i have no clue whats wrong. i tried to submit the code as a question at https://stackoverflow.com but there at the snippet the code is working just fine... any suggestions? how can i test if my php is working at all?
26th Nov 2018, 2:03 PM
pap
pap - avatar
+ 3
Ipang i tryed it. still nothing. i recreated all files - html and the php - i saved those in the htdocs, i restarted the apache and mysql, the internet connection was fine and still nothing. when i submit the form it doest echo the field values but it shows the whole php file as html/code. it is my first php project and i desided to try it with this aimple form with 2 inputs, because i have a project with an html with over 25 forms with over 350 inputs... i work on win 10(unfortunatelly). can there be some config issues? how can i test if the instalation is correct? thanks in advance
27th Nov 2018, 8:51 PM
pap
pap - avatar
+ 3
Im realy greatful for ypur efforts guys! Lexus Collins - I tried it. Not working 😞 Ipang so I tried it. The Installation is OK. I see the XAMPP welcome screen and when I open an PHP file, located in the htdocs it works. I tried also the info.php as you suggested and it worked also. It showed like 20 pagest php info. But my problem persists. I added also a .htaccess file as Lexus Collins suggested but still nothing. Now im sure that something is not ok with the configuration here. Any idea? ipang - here are the codes: html https://code.sololearn.com/WYhlOV0IGo0C/?ref=app php https://code.sololearn.com/w0UQFZ7H74Ud/?ref=app
29th Nov 2018, 12:21 AM
pap
pap - avatar
+ 2
if your output is the user & pass, then it is executing correctly. php returns output in html, so the browser does not know if it came from the Apache server. just know the php did return dynamic output, because you can return the pass first, in a different color, put to a database, etc. if u only get the file in text format, then the web server is not on.
25th Nov 2018, 4:25 PM
chuong
+ 2
at first please start the mysql in XAMPP server. Then try it
26th Nov 2018, 2:16 AM
Akshay
+ 2
It can be also that the php files aren't associated with php interpreter for some reason. Try making .htaccess file in directory with the file and write in it AddType application/x-httpd-php php In it. All in one line. If it doesn't help I've no idea. Maybe try to run it on another computer
28th Nov 2018, 7:56 AM
Draumri
Draumri - avatar
+ 2
chuong DOCTYPE has nothing about php execution
28th Nov 2018, 7:57 AM
Draumri
Draumri - avatar
+ 2
congrats pap. great job for not giving up
30th Nov 2018, 12:03 PM
chuong
+ 1
chuong nope.
27th Nov 2018, 8:42 PM
pap
pap - avatar
- 1
aims
26th Nov 2018, 8:14 AM
Rahul
- 1
you
26th Nov 2018, 8:15 AM
Rahul
- 3
HELLO
25th Nov 2018, 6:11 PM
DASTURCHU