sending data using localhost iis and php - php

I am having problems sending data using php. Im following some online tutorial for learning php and am having problems. I fairly certain php is running fine on my iis localhost as I ran a test index.php from localhost and everything came back as it should. I also uploaded the files to a web server where I know php is configured correctly. Im guessing that my problem is with syntax.
The text "your name is" and "You live at" is displayed fine but whatever is submitted is not showing up. I'm fairly certain that the problem is user error caused by yours truly. Any suggestions?
Here is the php file that contains the form:
<html>
<head>
<title><?php echo "Form test";?></title>
</head>
<body>
<form action="http://localhost/php/phptest1.php" method="post">
<p>Name:
<input type="text" id="name" size="30 "value="">
</p>
<p>Address:
<input type="text" id="address" size="30" value="">
</p>
</form>
</body>
</html>
And here his the php file to receive the data:
<html>
<head>
<title><?php echo "I have the Info";?></title>
</head>
<body>
<?php
echo "Your name is: ", $_POST['name'], "<br />";
echo "You live at: ", $_POST['address'], "<br />";
?>
</body>
</html>

You have to use the name attribute instead of id:
<input type="text" name="name" size="30" value="">

The reason why your code is not working the way you wanted it to, is that you have 2 errors in your naming convention.
The form fields need to have the name="some_name" added ("some_name" as an example).
Change
<input type="text" id="name" size="30 "value="">
to:
<input type="text" name="name" id="name" size="30 "value="">
and
<input type="text" id="address" size="30" value="">
to:
<input type="text" name="address" id="address" size="30" value="">
Full form code:
<html>
<head>
<title><?php echo "Form test";?></title>
</head>
<body>
<form action="http://localhost/php/phptest1.php" method="post">
<p>Name:
<input type="text" name="name" id="name" size="30 "value="">
</p>
<p>Address:
<input type="text" name="address" id="address" size="30" value="">
</p>
</form>
</body>
</html>
Added note: id can be kept in the OP's code to be used for styling in CSS, which can be kept if needed for styling later down the road.
id="name" and id="address" can safely be removed.

Related

HTML and PHP - How to seperate 2 forms on a single page?

I'm pretty new to HTML and currently I'm making an assignment where I have to make a HTML Form for data input and write the input to a file using PHP.
The writing to file works, but I getting the following comment on my code:
You have tested whether something has been posted, but what happens to your code if there are 2 forms on your page?
I kinda know what is being meant with this, but I am not that fluent to know how to solve this issue or where this comes from in my code.. Does this has to do with the action of the form set to $_SERVER["PHP_SELF"], the name of the submit button set wrong or anything else?
I've tried looking online for HTML forms and how to have 2 on the same page.. but I could not find anything really helpfull. If anyone can help or maybe point me to some info that explains this in detail (and with examples preferably) that would be great!
Here is just my HTML form as I have it with the PHP part checking for the submit. Rest of the code I left out as it is not relevant..
<html>
<head>
<title>Save and show data</title>
</head>
<body>
<h2>Fill in the form below</h2>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<label for='address'>Adres:</label><br>
<input type="text" id="address" name="address" placeholder = "Sunset lane 10" required><br>
<label for='zip'>Postcode:</label><br>
<input type="text" id="zip" name="zip" placeholder = "15922" required><br>
<label for='residence'>Woonplaats:</label><br>
<input type="text" id="woonplaats" name="woonplaats" placeholder = "Somewhere" required><br>
<label for='phone'>Telefoonnummer:</label><br>
<input type="tel" id="phone" name="phone" placeholder = "0678945124" required><br>
<label for='email'>E-mail:</label><br>
<input type="email" id="email" name="email" placeholder = "johndoe#email.com" required><br><br>
<input type="submit" name="submit_data" value="Save"><br>
</form>
<?php
if(isset($_POST["submit_data"]))
{
// magic stuff happens here
}
Do you mean something like this? Each submit button has its own validation.
<?php
if (isset($_POST['submit_data'])) {
//first form
}
if (isset($_POST['edit_data'])) {
//second form
}
?>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<input type="submit" name="submit_data" value="Save"><br>
</form>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<input type="submit" name="edit_data" value="Edit"><br>
</form>

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...

HTML form not sending POST data (or PHP not receiving it)

Yes, forms of this question are asked all the time. Due to the infinite possible ways that one can construct a form/php pair, my question still is different. (and much simpler)
I have:
<html>
<body>
<form id="request-inspecton" action="test_form_processor.php" method="POST">
<label class="text-label" for="FirstName">*first name:</label>
<input class="text-input" type="text" name="FirstName" id="FirstName" required="required" placeholder="First Name">
<label class="text-label" for="LastName">*last name:</label>
<input class="text-input" type="text" name="LastName" id="LastName" required="required" placeholder="Last Name">
<input class="button-input" type="submit" value="send" id="buttonSend" name="submitForm" placeholder="Submit form" value="POST">
</form>
</body>
</html>
and:
<?php
var_dump($_POST);
print $_POST["FirstName"];
?>
But all I get is:
array(0) { }
Golly, I just can't figure out what is wrong!\
Incidentally, example currently at:
http://checkitouthomeinspection.com/test_form.html
Strangely enough, it now works in both FF and Chrome. Beats me what the problem was. Thanks for the help. Case closed.

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.

trying to post to php file - server error

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

Categories