Post: PHP Tutorial - Forms
01-04-2013, 09:04 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); To make a working form on a webpage, php is used most of the time. Here I will teach you a simple way of displaying form data. No databases are needed for this. This is my first time making a tutorial....

First you need to make the actual form in HTML.
    
<html>
<body>
<form action="process.php" method="post">
Name: <input type="text" name="name">
Favorite Animal: <input type="text" name="animal">
<input type="submit">
</form>
</body>
</html>


When you hit the submit button it will post the form data to the process.php file on the server. You can post the information to the same file but it is more organized to post to an external file.

Now you need the 'process.php' file.

    
<?php
$name = $_POST["name"];
$animal = $_POST["animal"];
?>

<html>
Hello, <?php echo $name; ?>.<br>
Your favorite animal is a <?php echo $animal; ?>.
</html>


First in this file we define the variables '$name' and '$animal'. These variables call for the information from the form. The '$name' variable only calls for the input that has the name 'name'. Animal does the same thing but only for the input named 'animal'. Naming is important and you do not want to get mixed up with them, especially when making forms with database access. After defining variables we have a html portion that will display whatever you or anyone else submitted with the form. You use <?php and ?> tags to start and end a portion with php content. 'echo' is a function that shows what is defined in parenthesis or from a variable. (very useful)

With MYSQL data bases you can store this information and then call it out later. Reply please if you need a tutorial on that.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo