trying to post to php file - server error - php

I'm a newbie here to php and Apache.
I have an html form:
<html>
<body>
<?php
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>
I have contact.php located in what I believe is the right place, but when I submit the query, I get "The HTTP verb POST used to access path '/www/contact.php' is not allowed."
When I access contact.php as a url I get strange results (like a repeating File Download message box asking whether I want to Save or Open)

if you are using which is missing in your code.
for your below code will work.
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>

First Thing Give Name to Submit Button and second remove
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit" name="submit" /> </form>
</body>
</html>
and if you can still face an error then try to give full file path in action

Related

same page post request in php isset check not working?

Trying to get a simple isset form submit to check if the post request had been clicked from within the same page, but I can't get it working?
<?php
if(isset($_POST['btnSubmit'])){
echo "ok";
}
?>
<form id="form" name="form" action="">
<fieldset>
<legend>
<label for="fullName">Name</label>
</legend>
<input placeholder="Your name" type="text" name="fullName" id="fullName" autofocus>
</fieldset>
<fieldset>
<legend>
<label for="query">Message</label>
</legend>
<textarea placeholder="Type your Message Here...." name="query" id="query"></textarea>
</fieldset>
<input name="btnSubmit" type="submit" id="api-submit" value="Submit" />
</form>
I would expect this just to echo "ok" out onto the page? I've also cut out a lot of unessicary code from my actual work, as im just testing the principle here. But I think I musn't understand how it works, as it is sending the form contents to the URL, but just I don't know how to run seperate php code after the submit button had been clicked.
In your form you haven't specified that it is a POST request and by default, the method will be GET. You'll need to add the method="POST" to your form
<form id="form" name="form" action="" method="POST">
<fieldset>
<legend>
<label for="fullName">Name</label>
</legend>
<input placeholder="Your name" type="text" name="fullName" id="fullName" autofocus>
</fieldset>
<fieldset>
<legend>
<label for="query">Message</label>
</legend>
<textarea placeholder="Type your Message Here...." name="query" id="query">
</textarea>
</fieldset>
<input name="btnSubmit" type="submit" id="api-submit" value="Submit" />
</form>

Form Emailing in HTML and PHP not working

i have created a form on my website that lets others contact me. I used a PHP script to send the email but i always get the error:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
I used this code:
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john#example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
In html and this:
<?php
if($_POST["message"]) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
In the PHP file.
Any help?
You are POSTing comments, not message.
Change this:
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
to this:
<textarea name="message" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
Change your html with this, As you are using $_POST["message"] but you are not passing it in your html.. So change your this line
<input type="submit" name="message" value="Send">
complete code below:
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john#example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" name="message" value="Send">
<input type="reset" value="Reset">
</form>
The PHP will not send the mail because there is no input : message
You can use :
<?php
if(isset($_POST["message"])) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
And
<input type="submit" name="message" />
Try this code in your contact.php file:
<?php
if($_POST["comments"]) {
mail("myemail#example.com", "MCPEmaps Comment", $_POST["message"], "From: an#email.address");
}
?>
If in case you are using in localhost you need to work lot in your php.ini file. otherwise you get result.

PHP showing up as plain text

I have a simple form and php file. When I click submit it just pulls up a plain text file with the contents of resources.php. Why would this be happening?
index.html
<html>
<head>
</head>
<body>
<form action="resources.php" method='POST'>
<input type="text" placeholder="Name" name="name"><br>
<input type="text" placeholder="Organization" name="organization"><br>
<input type="email" placeholder="E-Mail" name="email"><br>
<input type="text" placeholder="Street Address" name="streetaddress"><br>
<input type="text" placeholder="Phone Number" name="phonenumber"><br>
<input type="text" placeholder="What is three plus four?" name="human"><br>
<input type="submit">
</form>
</body>
</html>
and the resources.php file...
<html>
<head></head>
<body>
<?php
echo '<pre>'.$_POST.'<pre>';
?>
</body>
</html>
Thanks.
Here are possible answers to your problem:
WEB server is not processing your PHP code correctly because php is not installed or misconfigured.
You're not using the web server at all. Make sure to load your pages from localhost (or whatever your server is) and not from the file itself
ex: localhost/path/to/index.html
and not c://program files...

How do I echo submitted values from settings.php to mainpage.php?

I'm basically trying to get the values submitted from settings so that when the user submits it, it is displayed onto mainpage.php. Here's the code from what I have in settings.php...
<html>
<head><title></title></head>
<body>
Logout
Main Page
<form action="" method="get">
<b>Bio</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="bio">
</form>
<form action="" method="get">
<b>Hobbies</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="hobbies">
</form>
<form action="" method="get">
<b>Past School</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="school">
</form>
<form action="" method="get">
<b>Work History</b>
<br>
<textarea rows="5" cols="20" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="work">
</form>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Choose Profile Picture:</label>
<input type="file" name="file" id="file">
<input type="submit" name="pic" value="Submit">
</form>
</body>
</html>
And this is what I have for mainpage.php
<?php
?>
<html>
<head><title></title></head>
<body>
Logout
Settings
</body>
</html>
Any suggestions?
As Jenna R said, it is better to use POST, not GET.
Then each variable is referenced with $_POST["name"], so $_POST["result"] and so on.
I suggest you start reading up on PHP and submitting forms securely if you are doing this for anything other than learning. This is pretty basic, so it looks like you haven't opened up the manual or a book just yet.

HTML form PHP post not working

I'm writing a little website for myself and I'm having trouble with what seems like a simple line of code:
form action="send.php" method="post"
Furthermore, even a simple line like form action="http://www.google.com"> isn't working. Here is my code:
<html>
<head>
<title>
AnonMail!
</title>
</head>
<body style="font-family:'Tahoma';>
<form action="send.php" method="post">
<label for="from">From: </label><input type="text" name="from" id="from"></input></br>
<label for="to">To: </label><input type="text" name="to" id="to"></input></br>
<label for="subj">Subject: </label><input type="text" name="subj" id="subj"></input></br>
<textarea rows=10 cols=100 name="message"></textarea></br>
<input type="submit" value="Send"/>
</form>
</body>
</html>
The error starts with your body tag.
You have not closed your double quotes in the style tag of your body.
Just close it properly and then run it.
I think that is only the problem.
Here's a form that should work:
<html>
<body>
<form action="contact.php" method="post">
<p><b>Your Name:</b> <input type="text" name="yourname" /><br />
<b>Subject:</b> <input type="text" name="subject" /><br />
<b>E-mail:</b> <input type="text" name="email" /><br />
Website: <input type="text" name="website"></p>
<p><input type="submit" value="Send it!"></p>
</form>
</body>
</html>
If you're still having troubles: http://myphpform.com/php-form-not-working.php
browsers show warnings when your action refers to an external source. Some browsers do not post form at all. This is unsafe for users.

Categories