I am very very new to PHP, but I have looked everywhere (it seems) and cannot figure out how to run a simple PHP script on an HTML webpage using Apache. I am pretty sure I am doing something wrong or missing a step. I have a contact form. I have the .html with action=example.php.
<form name="htmlform" method="post" action="../../../../../../xampp2/php/www/html_form_send.php">
I tried putting the html_form_send.php file in both the php/www and the htdocs folder.
Do I need to put the .html file in a different folder as well?
I tried changing the httpd.conf, but that did not seem to work either.
Oh, and Apache is running. What am I missing? I would really appreciate your help! Thank you!!
UPDATE:
Thank you all for your help! I really appreciate it. I decided to use a different contact form, and it works just fine. I am still not exactly sure what all was wrong with the other one. However, I really appreciate the help and your answers did help clear up some questions I had. Thanks!
Inside the xaamp/htdocs
create folder and put all the .html and .php files
Then in .html file give form action='html_form_send.php'
You may not run php on a html page.
PHP would run if you have a .php file having the php code on the server.
In XAMPP :
Save your .php in htdocs folder.
Start the XAMPP server and open the .php from the browser using : localhost/<file_name>.php
You may also create folders inside htdocs to store php files and later open it as localhost/<folder_name>/<file_name>.php from your browser.
Also form form action just use ./file.php to redirect to file.php found in same folder or ../<folder>/file.php to redirect to file.php in another folder present in the parent directory.
You can not put php script on a html page. You need to create a new page and make it a php page of its own.
From your question i see you're using xamp. Create two different pages Eg Form_Receive.php (which will receive all the information sent from your form) and a different page to hold your form Eg. From_Post.php(which will hold the form and send all the information via POST or GET method.
Also be mindful of the url of the "form action" in your form. Once it points to the wrong directory or file, all information will be posted wrongly.
Related
I have a new install. Ubuntu 22.04, Apache2, PHP 8.1 and I'm trying to use PHPMailer. My test page with phpinfo all looks good and shows the includes directory /usr/share/php. My form and script are in a subfolder of my document root and it loads fine. But when I fill out the form and the script starts it errors out unable to find PHPMailer. It's only looking in the subfolder the script is in, not the global includes directory. I don't want to put the mod in every form folder and I know it's supposed to work from the includes folder. Is this an Apache or php config issue? Or something I have to specify in the vhost?
Just verifying and closing out with the answer
I found the issue early today. Thanks to bad/tired eyes, I wasn't seeing the leading dot so it was looking for ./usr... Once i fixed that i was able to sort out the Ubuntu method of calling it from the libphp-phpmailer pkg autoload.php. I was able to get the script working with a few code corrections. The only thing I didn't sort out was PHPMailer:ParseAdresses but i only had a few recipients for this form so it wasn't that big an issue. My form is back online and my managers are happy 😊
My page in wordpress have a button like "Go to the next".
I am trying to get my php file run by clicking the button.
<form action="https://"domain name".com/hoge.php" method="POST"></form>
The php file is successfully run if I locate the php file in the domain.
(like, https://"domain name".com/hoge.php)
However, the php file can not be run if I locate the file in the themes folder, and the response is 404 not found.
(like, https://"domain name".com/public_html/wp-content/themes/hoge.php)
So I have 2 questions.
Why the php file can not be accessed if I locate the file in the themes folder?
Talking about security, is it safe to locate my php file in the domain directly?
(like, https://"domain name".com/hoge.php)
wp-content implies this is a WordPress Site.
Wordpress changes the .htaccess to prevent exactly this. The htaccess will not let you access the sub php files directly.
Answer for question 1:
There has a lot factor affecting to located your file. It might involved to the RewriteRule for .htaccess configuration, your platform configuration or just you create file at wrong location or wrong name
Answer for question 2:
Yes, it is unsafe, because it can be access by anyone else. So you need to perform some authenticate checking before execute the written code, for example use SESSION to check the user is already logged in before execute your code.
Your way of handling FORM is perfectly ok, while developing in core PHP. But, WordPress has its own handling FORM. YOu can check out this blog on how to handle the FORM in WordPress way.
Sorry if this is a simple question, but I have been having some problems with my website. I have used both HostGator and Godaddy to host my site. But on both site I have been getting a consistent problem, image: http://postimg.org/image/optvm8qy7/ (sorry for links i did not want to clog up the page).
My problem, or what I think that my problem, is that my default file that we website reads is index.php. I know that that is usable and it dose work on my localhost server. But the index.php file contains both php and html code inside it: http://postimg.org/image/79eyw0fvt/ (once again sorry for the link and not an image on the page).
So what I am Thinking is that for some reason the Web host cant read the php code or is reading it as regular text. Because as you can see the title of the webpage is meant to say "Jackpot Battles", but it says <?php echo $tital; ?>. The thing is that it will read the rest of the files and the website correctly just not any php.
If anyone has any ideas on what could be causing this, or would like any extra information please leave a comment.
Thank you for your time.
It looks like the default page for your host is index.html. While index.php might be on the list, because you have an index.html file it is pointing to that. If you delete or rename index.html it will likely work. I can view what looks to be the correct data by going to http://jackpotbattles.pw/index.php
So I've been searching all over the internet for a solution to my problem and I've tried just about everything I could find, but still nothing is working.
My problem is that when I open a .php file in chromium by using:
localhost/filename.php
it works fine. If I put the file in a subdirectory and access it as such:
localhost/subdirectory/filename.php
it works fine as well. The problem comes when I try to access the .php file in the subdirectory from another file. For example I have an entire project located under:
var/www/test
with the index.html sitting in that folder and then the .php scripts in a folder located at:
var/www/test/php_scripts
In the HMTL file there is a form that sends the form data to one of said .php scripts and when I click the submit button it downloads the .php script instead of navigating to it and executing in the browser.
I tried moving the script into the "test" folder so it was with the index.html file and that didn't fix anything. If I place everything in:
var/www
it all works fine. But I don't want to do that because then I have to deal with a cluttered mess of files which no one likes doing...
I did search for the past couple hours all over stack exchange and other sites and couldn't find anything that worked. If this is a duplicate question then please point me in the direction of the answer, if not, hopefully one of you jedi coders can solve my headache.
Thanks,
Zak
It sounds like you need to look at the action part of your html form.
Make sure that the action starts with a /
Example
<form action="/php_scripts/script_name.php>
I have an index.html in my wampserver www directory. On this html, there is a link for a user to upload file. When I hit the link, I select files to upload but instead of the uploadmanager.php which i have tested in my eclipse debugg environment to work, it displays the some part of the code on the web page without doing anything thing. This is not what I expect. Can someone please tell me what is wrong? Thank you.
sound like you are using php-short-open-tags (<? instead of <?php) without enabling this in your php.ini. change your php.ini or use the standart open-tags to solve this.
Are you sure you enabled PHP in WAMP?
Try creating a new uploadmanager.php file directly in wamp/www (or whatever subdirectory) and paste the code from your tested uploadmanager script into the new file. Then try to run it in WAMP.
I think it is a permissions problem. I copied an index.php file into a c:/wamp/www/subdirectory and it only displayed the code. Once I created a new index.php file and pasted the contents of the old file into it, it worked perfectly.
Are you posting to the uploadmanager.php page? Are you getting an error or just seeing the code? Can you post the code from the index.html page that handled the form and the part of the php code you're seeing for us to look at?
Every now and then I have Apache serving the .php as downloadable files instead processing them on the server, but only with random requests.
Some reasons, why this might happen, are
PHP misconfiguration
PHP-files in a directory without execute rights
wrong content type sent
timeout from script execution
In my situation the last bullet is the most dangerous, but luckily it seems to show up only immediately after modifying some of the .php files. I haven't tracked the problem any deeper yet, but it seems to relate some filesystem level operations (as the disk I/O is a bottleneck) and presents itself only in testing env.