Hye there I'm new to PHP and learning to my own I have a simple HTML form as:
<form action="file:///C|/wamp/www/welcome.php" method="POST">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
and my PHP file is:
<body>
HELLO
<?php
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
?>
</body>
the problem is that when i click on my submit button it only shows the following output:
HELLO Welcome .
You are years old!
I mean the output is not showing up the contents from the POST Function! so is it me doing something wrong or so. I am new to PHP and want to learn it can somebody help me please
thanks in advance!
The path for your form action must be a valid web path. Not a file path on your computer:
<form action="/welcome.php" method="POST">
or
<form action="http://localhost/welcome.php" method="POST">
You also mix HTML in your PHP which should be throwing you a syntax error. When you fix the above that will error out on you.
<body>
HELLO
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
</body>
Related
I am using Post form, which works perfectly with any text, but when try to post code like format=xhtml, redirect me to 404
I am on this already all night and can not solve it with google`s help.
It is PHP page
Works on the example page
https://tryphp.w3schools.com/showphp.php?filename=demo_form_post
Does not work on my server
I am posting
content="format=xhtml; url=https://m.1688.com/offer/42866153932.html" />
Here is the example code
<!DOCTYPE HTML>
<html>
<body>
<form action="test45.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
<?php
//include "fetchpage.php";
?>
<?php
echo "Welcome ";
echo $_POST['name'];
echo "<br> Your e-mail address is:$nbsp";
echo $_POST['email'];
?>
You need to understand php form handling first.
Please go through this link php form handling
OR
Just see the code below..
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-Mail: <input type="text" name="email"><br>
<input type="submit">
</form>
AND PHP CODE SHOULD LOOK LIKE THIS...
<?php
echo "Welcome ";
echo $_POST['name'];
echo "<br> Your e-mail address is: ";
echo $_POST['email'];
?>
Get it run on: CLICK HERE...
HOPE IT HELPS...
I've just started using PHP forms for my website prototype, and it wasn't working so I decided to try to make a basic form example. No fancy CSS, just pure data. This is the code.
Index.html
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>
<br />
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The code works as far as displaying the 'Welcome ___ Your email address is: ____.
It just doesn't display the data entered in the form. For clarification as to whether my PHP works, I have tried just displaying some text and it worked fine. I use the PHP Editor phpDesigner8.
Thanks!
I really don't know why my code isn't working! Let me clear it by example..
I got a file named 'index.html' example...
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="test">
<input type="submit">
</form>
</body>
</html>
And of course the form action file test.php .. example..
<?php
$something = ($_POST["test"]);
// from here I have some PHP codes and this "something" variable will be process in this codes and will print out something spacial..
?>
Now example If I post "Hello, It's not working" then the output will show a spacial design.
But Instead process, it's just printing out whatever I submit in that form.
But when I manually add the variable to "something" and if I execute the "test.php" . Example..
$something = "Hello, It's not working";
Then it works perfectly..
And yes. Also tried GET method.. It's still same as POST.
This is my first question here..
Thanks for any help and suggestions!
First Convert, index.html to php and follow this code:-
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" value="" name="test">
<input name="submit" value="submit" type="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$something = $_POST["test"];
}
?>
That's correct _POST:
<?php
//NO ($_POST["test"])
$something = $_POST["test"];
?>
Here is my Code :
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" action="../../../wamp/www/abc.php" method="get">
<input type="text" name="text1" id="username" />
<input type="submit" />
</form>
</body>
</html>
The abc.php file is located in C:/wamp/www/abc.php
<html>
<body>
Hello World
<?php
echo "Hello";
echo $_GET["username"];
?>
</body>
</html>
In the form, when I press the Submit button, only "Hello World" is displayed.
The value entered in the textbox is not displayed at all. Even the "Hello" message printed inside the php code is not displayed.
How can i display the Value ?
text1 is the name of your input, so the correct PHP code would be.
<?php
echo "Hello ";
echo $_GET['text1'];
?>
Try the below, get array is created using name attr not id one.
echo $_GET["text1"];
There is two solution for you should use :
First Way :Change your php code:
<?php
echo "hello";
echo $_GET["text1"];
?>
Second Way: Chnage your HTML
<input type="text" name="username" id="username"/>
If second "Hello" from echo is not displayed, there is a problem with your PHP installation.
I have a form on my homepage and when it is submitted, it takes users to another page on my site. I want to pass the form data entered to the next page, with something like:
<?php echo $email; ?>
Where $email is the email address the user entered into the form. How exactly do I accomplish this?
The best way to accomplish that is to use POST which is a method of Hypertext Transfer Protocol https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
index.php
<html>
<body>
<form action="site2.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">
</form>
</body>
</html>
site2.php
<html>
<body>
Hello <?php echo $_POST["name"]; ?>!<br>
Your mail is <?php echo $_POST["mail"]; ?>.
</body>
</html>
output
Hello "name" !
Your email is "whatyou#addedonindex.com" .