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...
Related
I am trying to save a Users data from an input field so that it can be displayed later in their profile of a webpage, for example the user inputs data of a cinema(name, address) and can see it later under Saved Restaurants and call up the previously saved information. Can the PHP and HTML code be written together in one .PHP file?
So far I have this:
<html lang>
<head>
<link rel="stylesheet" href="css/addOrEditCinemaPage.css">
</head>
<?php include "php/head.php" ?>
<?php include "php/navigation.php" ?>
<body>
<div class="myForm">
<form>
<h2>Add or Edit a Cinema</h2>
<label for="name"><b>Name of Cinema</b></label>
<input type="text" placeholder="Enter name">
<label for="str"><b>Street</b></label>
<input type="text" placeholder="Enter street">
<label for="nr"><b>Nr.</b></label>
<input type="number" placeholder="Enter Nr.">
<label for="plz"><b>Post Code</b></label>
<input type="number" placeholder="Enter Post Code"><br><br>
<label for="ct"><b>City</b></label>
<input type="text" placeholder="Enter City">
<label for="sta"><b>State</b></label>
<input type="text" placeholder="Enter State">
<label for="descr"><b>Description</b></label><br>
<textarea placeholder="Enter Discription"></textarea>
<div class="imagebutton">
Add Image
</div>
<button type="submit">Save</button>
</form>
</div>
<?php include "php/footer.php" ?>
</body>
</html>```
Can the PHP to save and display to input infomration also be written here?
Yes, you can by setting the 'action' attribute of the form to the same file, and by setting the 'method' attribute to POST.
Instead of using
<form>
use
<form action="<?PHP echo $_SERVER['php_self'];?>" method="POST">
Then, set the 'name' attribute of each input.
For example, Instead of using
<input type="text" placeholder="Enter name">
use
<input type="text" name="name" placeholder="Enter name">
You'll also have to set the 'name' attribute of the submit button to 'submit':
<button type="submit" name="submit">Save</button>
Once you've done that, the PHP code to access the form data would be:
if (isset($_POST['submit'])) {
echo $_POST['name'];
}
send your data with html to another php page
you must use get or post for sending form data to php page
like below
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.
I've used the exact files from this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
The ideea is to submit the form without refreshing, and displaying a nice animation after submission.
But when I try to use the files for my personalised form, the animation doesn't work on Chrome and Opera. Why?
<div id="contact_form">
<form name="contact" method="post" action="">
<p>Hi, my name is</p>
<input type="text" name="name" id="name" class="input" size="20" value="" class="text-input" />
<p> and my email is</p>
<input type="text" name="email" id="email" class="input" size="20" value="" class="text-input"/>
<p>More Random Text.</p>
<textarea name="message" id="message" class="input" onfocus="this.value='';" class="text-input"> ... </textarea>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</form>
</div>
Everything works ok in this fiddle:
http://jsfiddle.net/CTGa3/2/
Works in Firefox and Chrome. I am not using your php because I don't have access to it. Instead, I am doing a dummy ajax call via jsfiddle, but the result should be the same.
The only thing I could see is that you didn't include the code for runOnLoad. If you include the code, or remove the runOnLoad() call, everything works fine. That piece of code is outdated anyway, because jQuery can do that for us. You just have to move this line:
$("input#name").select().focus();
To the top of your jQuery code block:
http://jsfiddle.net/CTGa3/3/
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.
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