I have two files, testpage.html and testpage.php in the same folder.
This is testpage.html
<!DOCTYPE HTML>
<html>
<body>
<form action="testpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
This is testpage.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?><br>
</body>
</html>
The form seems to work okay but when I hit submit nothing shows up on the next page. no matter what I enter int he form, it always reads "Welcome" "Your email address is:" with nothing entered after that like its supposed to.
Do I have something configured incorrectly? Am I using the wrong browser (firefox)?
Thanks!
"I am accessing it via file:///C:/... should I be accessing it some other way instead?"
Just as I thought.
There you go. A web browser will not parse PHP directives that way.
It must be accessed as http://localhost/yourfile.xxx
Plus, a webserver and PHP need to be installed in order to parse PHP directives.
"I don't think I have Xampp or any virtual server set up... I'll look into that, any tips on where to start?"
You need to install one. Here are a few links to get you started and depending on the platform you are using.
https://www.apachefriends.org/
http://www.wampserver.com/
https://www.mamp.info
http://www.easyphp.org/
Pick your flavour.
Related
I'm just following w3schools like a normal person
For me getting php to work is harder than learning the language itself...
If somebody could please provide an extensive guide on common problems such as this one that would be heavily resourceful
I'd also like to know the ins and outs of running php scripts within an html context, not having the php extension on the browser would be preferred in most cases
I can't get the following script to run upon submitting the form. It ends up opening up a window asking me which program should be used to run the php file.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="name"> <br>
E-mail: <input type="text" name="email"> <br>
<input type="submit">
</body>
</form>
Opening the php file using firefox accomplishes the same thing.
If so, which program should I use? or do I need to update some configuration
in order to get this simple script to work
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
One of the easiest ways to get PHP up and running for a newbie would be to use XAMPP. See this Wikihow article on how to get that done: https://www.wikihow.com/Set-up-a-Personal-Web-Server-with-XAMPP
Good luck!
I'm just starting to learn form and PHP. I am testing a simple HTML file from W3Schools here with the following code:
<html>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
It is supposed to pass the information to a PHP file called welcome.php, which looks like this:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?><br>
Random thing: <?php $rand = "bananas"; echo "$rand"; ?>
</body>
</html>
When I run the HTML file on Chrome, fill in the name and the email and press submit, the page looks like this:
Welcome
Your email address is:
Random thing:
While the HTML part works, the name variable, email variable and rand variable isn't printed.
[EDIT]: I solved it by transferring the files to a server and running it by going onto the actual webpage and it worked. Also Azeez Kallayi suggested running it on Xamp.
I think you are not using any server, just opening in broswer without any server. Also correct semicolon as in the above comment.
Since PHP is a server side programming language , you need a server to execute the PHP scripts.
There are many applications available that you can use as local servers and run your application. Some of them are below.
Wamp, Xamp, Lamp
Hope this will help you
Change this
echo "$rand";
To this
echo $rand;
Firstly you should get knowledge what PHP is and how you can use it.
PHP is a server-side scripting language. So if you try to run it like a html file you will not see the expected output. You need to understand what is a server side server-side scripting is.
If you have have jumped into coding is very essential you should know how you should debug to resolve your error.
One easy way is to enable error reporting.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
Hope this will give you a start .
I'm a novice learning PHP and am stuck on a basic issue. It looks like a configuration issue. I reviewed stackoverflow, tutorials, and PhpStorm documentation, but was unable to find a simple answer.
I'm trying to get HTML form data to post a message upon submitting the form. There are two php files, the example.php has the php script, and the welcome.php file has the HTML with the php echo script. The HTML text information is returned, but Chrome throws an error notice, Notice: Undefined index: name in ... welcome.php on line 4, related to the submitted name and email array.
PhpStorm gives me a warning on the example.php file, form input
without associated label or form attribute. My conclusion is that PhpStorm is not associating the two files.
I'm using PHP 7.0.0, with C:\wamp64\bin\apache\apache2.4.17\htdocs
example.php
<!DOCTYPE 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
<!DOCTYPE HTML>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
PhpStorm has nothing to do with the error.
If you just go to welcome.php page it will give an error because there is no $_POST submission. You can check if there is any submission first.
Welcome.php
<!DOCTYPE HTML>
<html>
<body>
Welcome <?php if(isset($_POST['name'])){ echo $_POST["name"]; }?><br>
Your email address is: <?php if(isset($_POST['email'])) { echo $_POST["email"];} ?>
</body>
</html>
I'm following a beginners tutorial. I tried a basic echo, nothing displayed in the browser. It looks like this is part of my initial problem. No errors, no problem with the code. That's why I thought this was a problem with PhpStorm.
learnphp.php file
<!DOCTYPE HTML>
<html>
<head>
<title>Information Gathered
<body>
<?php
echo "<p>Data processed</p>";
?>
</body>
</html>
This was a configuration issue. PhpStorm was defaulting to the PhpStorm port and not port 80.
PhpStorm wasn't properly configured to work with the server. I uninstalled wamp and installed xampp, that didn't fix the problem, but gave me more control.
In Settings, Build, Execution, Deployment:
Type: Local or mounted folder is required because my project is on my D: drive, and server is on my C: drive
Mappings: Use this server as default button must be selected
Web path on server 'xampp': must be the project file folder
I have this two files:
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>
And welcome.php
<html>
<body>
Welcome, <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
This is example from there
When the user fills the form and hits "enter" it should display:
Welcome, the_name_you_enter
Your email address is address_you_enter
But for me it only displays welcome.php source code (I am using Safari 7).
Does anyone knows why?
It sounds like your calling up the page from a server that is not executing php.
This usually happens because the PHP file is not executed on a web server or PHP is not enabled on your webserver.
You are probably trying to access the file directly using file://
Take a look at MAMP (I am assuming you are using OS X)
I'm very new to php/html, and I'm trying to teach myself the basics of creating and processing an html form.
I created a folder called Website. In it I created an html file index.html. I also created a file submit.php.
(this code is taken from: http://www.w3schools.com/php/php_forms.asp)
In index.html I have:
<html>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
In submit.php I have:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
When I open the html file in chrome and fill in the blanks and press submit, I get redirected to a page with the code in submit.php:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
I should be getting this output:
Welcome Hannah
Your email address is Hannah#example.com
What am I doing wrong that the output isn't working?
Thanks!
PHP is processed on a server, so you can't treat it like HTML, it needs to be placed on a server that has apache installed. You can install one on your computer, using something like the following:
WAMP
LAMP
MAMP
XAMPP
Sounds like you are doing this via files on your desktop and not via a web server. Either on the Internet or via your local machine. I took your example 100% as presented, placed it within my htdocs folder in MAMP (LAMP for the Macintosh) and it behaves 100% as expected.
The difference between loading files on your desktop versus a web server is a web server will process the PHP. If you just do it as files, then the file gets loaded & doesn’t get parsed.