dear all
I am a beginer in PHP world (PHP 5.3.5) my web server is IIS fastCGI on win xp
I tried to pass values from the HTML form to the php but the data are not passed
this is my html file
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
and this is my php file welcome.php
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
After pressing submit the output was like this
Welcome!
You are years old.
but it should be like this
Welcome John!
You are 28 years old.
Can you please help me with this.
on IIS change in the form: method="post" to method="POST" <-- UPPERCASE should solve your issue.
Anyway what about the apache? and PHP version around just 5, flat five :)
5.3.5 on IIS for the beginner? sounds like to get the Mount Everest by night without gloves
That is pretty standard simple code, and looks correct. One thing you might look at is the way PHP is configured on your server. Also, try using $_REQUEST in place of $_POST on your welcome.php page and see if it still does the same thing.
Try naming your form as well
After looking at your code it seems that it must be a configuration issue.
Steps to resolve this:
Firstly is the code that spits out the page actually welcome.php
Secondly add the following to your php block
var_dump($_POST);
Click submit and if this still shows
array (
)
if so then do
var_dump($_REQUEST);
and post the contents to your post, and show us.
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 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.
I am creating an online order form for a wholesale nursery. I am trying to test the PHP locally and have successfully set up WAMP. When I test basic scripts, they run just fine but when I try using _POST to send data to variable from HTML input fields, nothing gets transferred to my PHP variables as noted when I try echoing them to a page. Is there something I need to do to test _POST and _GET methods locally that I don't know about?
I tried testing my ability to do so using a simple example I found at W3 schools:
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="fname"><br>
Age: <input type="text" name="age"><br>
<input type="submit">
</form>
</body>
</html>
Here is the PHP:
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br>
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
Like I said, I used WAMP and both files are located in the wamp/www/ folder.
First of all all forms need a method (get, post) and an action (where to send the data) in the html.
<form action='your/location.php' method='post'>
<input type='text' name='username'/>
<input type='submit' value='submit'/>
</form>
All inputs must have a name attribute this is for referencing data in the php script
<input type='text' name='username'/>
In your/location.php you will receive an array with the data under the name:
$_GET or $_POST depending on your method set in the form tag.
To access specific data use $_POST['username'] (replace username with any names set on any of the submitted form inputs)
To print out on the screen use
echo $_POST['username'];
Check if your file is under the extension .php and has the name test
If you get partial output and by partial i mean only the html part start you php server Apache or Nginx or whatever wamp uses, it might not start with all the functionality without specified to do so.
Make sure you open the page under localhost if you are testing it separately.
If for some reason you can't seem to get wamp to work try xampp which is similar and in my opinion better and never failed me.
I'm new to web development and have been wrestling with this problem for several hours now, so I've decided to turn to your wisdom. I'm trying to design a little webpage with a database for my wife to store her recipes in, but I'm having trouble getting form submission to work. Here is the code for the webpage where I take the form information in:
<html><body>
Enter the information below to add a new ingredient for use in your recipes.
<form action="add_to_database.php" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
</body></html>
And here is some silly code I've been trying to display on the page to see if I can even get the form submission to work:
<html><body>
<?php
$name = $_POST['name'];
echo $name."<br />";
?>
</body></html>
Unfortunately, the page comes back as completely back (after I hit the submit button). What's absolutely baffling to me is that I've copied and pasted the examples from this page into some files and everything seems to work fine. So it seems as though apache and php are working correctly, but I'm messing up somewhere along the way. My apologies in advance if this seems like a stupid question but for the life of me I can't figure it out.
Do you name the other file as add_to_database.php where the form is submitted. Instead you can test on teh same page by removing the add_to_database.php from the form action.
form action="" method="post">
Name: <input name="name" type="text" />
Serving: <input type="text" name="serving" />
Calories: <input type="text" name="calories" />
<input type="submit" />
</form>
and write the php code on the same page as
$name = $_POST['name'];
echo $name;
If this is not working for you. Create a php file named test.php and type phpinfo(); there.
Verify that your page is indeed being processed by PHP - obvious question, but does your PHP file have a .php extension? Do other things like phpinfo() or echo "Test"; work?
Check the error log in /var/log/apache2/error.log or similar (if on Linux, dunno where that'd be on Windows).
Try turning display_errors on in the PHP configuration (this is a good idea only for a development install, not a production server).
a bit of a longshot, but if you can verify that php is pro essing the page. Clean up your html, you are missing the dtd, head, and encoding. . hard to say how a browser is going to interpret a form (missing a name attribute) without these.