html form action to php gives error 500 - php

I am just starting out with PHP, and want to get my HTML/javascript form to email via PHP.
So, the bits of the code that are relevant (both in same HTML document):-
(web address changed to protect the innocent, but they are both the same (cut/paste) in real life.)
<form id=emailform method="post" action="http://www.qqqqqqqq.co.uk/PHP/TestPHP.php" enctype="multipart/form-data" accept-charset="UTF-8">
This gives:- Error 500 - Internal server error
Test PHP
This runs the PHP code.
The PHP, which in this case is a simple echo, as the error occurs with any PHP I have, is:-
<html>
<body>
<?php
/* phpinfo(); */
echo "This is a Test PHP echo test"; ?>
</body>
</html>
Have I done something really daft ? I thought that the action (if form valid) would behave similar to the link hence the second test.

One thing that might help, putting quotes around your form's ID, also,
<form id="emailform" method="post" action="http://www.qqqqqqqq.co.uk/PHP/TestPHP.php" enctype="multipart/form-data" accept-charset="UTF-8">
A 500 error means "something has gone wrong on the web site's server but the server could not be more specific on what the exact problem is" - about.com
Try putting the quotes around the ID, and let us know what happens. That for some reason is a common mistake I make a lot, and I get the same issue.
http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm

Related

$_POST request not being handled by the server

I have a form with one text input field:
index.html
<form method="post" action="comment.php">
<a href="javascript:void(0)">
<div class="avatar" style="background:url('img/user4561.jpg') center/cover"></div>
</a>
<input name="comm" type="text"/>
<input type="submit" value="submit"/>
</form>
And here is comment.php in the same directory
<?php
echo $_POST["comm"];
?>
Now the most incredible event. The form data does not get submitted! I get an error:
Notice: Undefined index: comm in 192.168.0.1/comment.php on line 2
I changed comment.php like this:
<?php
if(isset($_POST["comm"])) {
echo "It is set";
} else {
echo "It is not set";
}
?>
and I get:
It is not set
So, I copied the HTML code of the form into another blank webpage. I also changed the action attribute of the form to "192.168.0.1/comment.php". Now I get
It is set
I also tried using GET instead of POST, but I am again in the same conflict.
EDIT: I removed all other files and code, except for the form and its script. The problem persists. You can now read and modify the source code. Go to files.000webhost.com. Use chatstack as the website name and 6RxOkuJ1CIkbNqxKUMGr as the password.
EDIT: I modified the code for the form above to exactly match that in the above given link. I noticed that removing the link from inside the form solves the problem. I have already done this, but this is so weird. According to this post it is totally fine to have other elements inside a <form> element. There are also other parts of my website where I have <div> elements inside a form element and the form is working fine.
What is this? Is it the server or something else?
I am pretty sure the information provided here is not enough. Feel free to ask for any additional information. There is just too much information to write in a post, and I don't know which part of it is relevant.
Open your dev-console in browser.
Go to the network tab. Now you fill in your form and submit. After your comment.php is loaded, you check for the very first row in the network tab (should be the comment.php html document).
When you click on that request it should display you, whether the request was GET or POST and also what data were sent to this document.
You can also try at comment.php var_dump($_REQUEST); to see what data were sent and how it can be accessed.
By this you can see if server all over receives any data. If yes, then you go for an other server like apache2 for testing purpose to look if bug is fixed.
That's how I would to that, but I suspect that by editing your code for the public, you accidentally withheld some information that would solve this simple problem.
It's very unlikely that web-servers like WAMP had passed the testing environment before publishing a new version allthough no data could be procesed by server

PhP form posts normally (data received on e-mail) but displays FORM.PHP PAGE NOT FOUND

Everything works well behind the scene but my clients see a Page not found after Posting a form.
The form.php must have been found otherwise the data wouldn't be parsed to my e-mail smoothly. I have a redirection page: thankpage.html, which is up and running well when I type its address directly.
what could be going on? any help please?
Anyway,
Instead of calling the Thankpage.html from the form.php, I inserted the following into my "form" element in the contact.html page itself:
onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';"
So it is now:
<form role="form" id="contact-form" method="post" action="form.php" onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';">
Somehow it's all working well and I have no "PAGE NOT FOUND" messages!!!
Sorry if I wasn't clear on the question, it's my first one as you can see... cheers!

Actions used in form making in php

I created a form in php named form.php, gave the error statements in the same file. I created another php file named test.php which connects form.php to my local database and submits the data. Now in form.php if I use
form action="test.php" method="post" name="form1"
it directly submits data into the database without judging or showing the errors, if I use
form action=" htmlspecialchars($_SERVER["PHP_SELF"])" method="post" name="form1"
then it judge and shows the errors but does not submit the data to my database.
Please help me in this regard.
It seems you've written the errors checking and validation conditions in your 'form.php' script, and connections with your db are done through the 'test.php'.
A better way would be to keep everything on the same file. Move your connection code to form script, and that should work.
The reason is if you write form action="test.php" method="post" name="form1"
the values of the form are directly transferred to the test.php, and no code of form.php is interpreted. When you do the latter, the test.php isn't considered at all, because it doesn't get any info saying that go to that file.

Submit form to a directory (example.com/product/), form action=""?

I've tried <form action="/product/" method="get">, but it doesn't work.
Usually I would have a PHP file such as search.php in the same directory such that <form action="search.php", but I'm implementing a different kind of search which needs to always send the request to the same place.
What I'm getting: (e.g. if I'm on page example.com/product/foo)
example.com/product/foo?id={query};
What I want: example.com/product/?id={query};
Update: Upon instpecting the elements, it seems like it's my action=" product ". Something's up with the slashes. I checked the source code, and it seems fine.
Got it to work after changing double quotes to single quotes... <form action="/product/" method="get">.
Use full url in the action...
eg
<form action="http://example.com/product/" method="get">
...

Posting from IE8 to PHP gives blank $_POST

I have a simple HTML form, sending a post request to a php script. In IE8, the form only works intermittently - most of the time the PHP script sees an empty $_POST variable.
Here's my code:
<html>
<head>
<title>Post test</title>
</head>
<body style="text-align: center;">
<?php
echo "<pre>".print_r($_POST, TRUE)."</pre>";
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="name">
<input type="hidden" name="hidden" value="moo" >
<input type="submit" value="Search" >
</form>
</body>
</html>
Sometimes the print_r gives the response you'd expect (i.e. it's populated with the data from the form), most of the time it's empty.
Not being able to use POST is a bit of a problem for web applications - anyone got any ideas what's going on, and how to fix it?
Thanks everyone for wading in on this one.
It turns out the problem lay in an Apache module I had enabled.
It's a module to allow apache to use Windows authentication to identify a user via their Windows User id - mod_auth_sspi
The effect is caused by a known bug, in the module, but with a simple extra directive this can be worked around, until a fix is added in the next update, as described here:
http://sourceforge.net/projects/mod-auth-sspi/forums/forum/550583/topic/3392037
That sounds very very bizarre. Does it happen in other versions of IE as well?
I can't tell you what the problem is, but here are my suggestions on how to diagnose it:
Print $_REQUEST rather than just $_POST, to see if the data is coming in via another method.
Use a tool like Fiddler or Wireshark to track exactly what is actually being sent by the browser.
Fiddler in particular has been very helpful for me a few times (mainly when debugging Ajax code), and will tell you exactly what was posted by the browser. If your web server is localhost, you can also use Fiddler to track what is received before PHP gets its hands on it. If not, you can use wireshark on the server if you have permissions for installing that sort of thing.
In addition to Fiddler, I would have suggested a browser-based tool like Firebug, but I don't know of one for IE that is good enough (The IE dev toolbar doesn't give you details of request and response data, as far as I know).
I'm suspicious that when the script is telling you that $_POST is empty, you did not actually POST the form. You can check by adding print($_SERVER['REQUEST_METHOD']); after your print_r($_POST);
If you are posting a file some of the time (i.e. with a file input) then make sure you set enctype="multipart/form-data" in your <form> element.
Have you checked the generated html? Is it possible that echo $_SERVER['PHP_SELF'] isn't producing the output you're after, which messes up the form html, which messes up the POST?

Categories