Create a Sign Up Page using PHP beginner Tutorial

Alright, let’s jump in make your first PHP enabled page! we are going to make a simple sign up page. Today I‘ll show you how to use the data entered in a page using php. In the next part we will cover how to store, read, update and delete the entered data. Let’s begin.First let’s build a sign up form. Create a file, name it signup.php and write the following code in it.

<html>
<head>
<title>Sign Up</title>
</head>
<body>
<? php
include(“classes/class.user.php”);
/*
The include statement includes and evaluates the specified file.
We have included in here because we will call the function contained in class.user.php in this file.
You can read more about include here.
*/
$n = new user ();
//storing a new instance of user class in $n. User class is in the file included above.
//variables in PHP start with $ sign.
if(isset($_POST[‘submit’]))
/*
POST is a method of passing data between scripts. Note the method in form tag in html below, it is set to post , so any “input” in this form will be saved in $_POST array. isset checks if $_POST is null o not.
*/
{
      $n->signup();
      // Pointing to the signup function of the User class object stored in $n.
}
else
{

?>
//Now building the form using html

<p><font size=”+2″>Sign Up:</font></p>
<form name=”form1″ method=”post” action=””>
// the post method submits data to be processed to another resource, it’s better for sensitive data as //the data of form is not shown in URL, if you use get method, data is shown in URL.
<table width=”75%” border=”0″>
<tr> 
<td width=”27%”>Username</td>
<td width=”73%”><input type=”text” name=”username”></td>
</tr>
<tr> 
<td width=”27%”>Email</td>
<td width=”73%”><input type=”text” name=”email”></td>
</tr>
<tr> 
<td width=”27%”>Address</td>
<td width=”73%”><input type=”text” name=”address”></td>
</tr>
<tr> 
<td width=”27%”>Phone</td>
<td width=”73%”><input type=”text” name=”phone”></td>
</tr>
<tr> 
<td>Password</td>
<td><input type=”password” name=”password”></td>
</tr>
<tr> 
<td>&nbsp;</td>
<td><input type=”submit” name=”submit” value=”Submit”></td>
</tr>
</table>
</form>

<?php
}
?>
</body>
</html>

Now let’s build the User class. First we’ll make a file named user.class.php, there’s no hard and fast rules for naming but it’s better to use standard conventions. Write the following code in the file.
<?php

class user {

        function __construct() {
        echo”no one called me <br>”; 
// echo displays the contents that’s written in quotes.
// the statements in construct function are executed as soon as an instance of class is created even if 
// it’s not called
       
    }
    function signup() {
//storing the data entered by the user in local variables, remember $_POST? check the comments on //top
        $user = $_POST[‘username’];
        $email = $_POST[’email’];
        $phone = $_POST[‘phone’];
        $address = $_POST[‘address’];
        $pass = $_POST[‘password’];
        echo ‘<br>’ . $user;
        echo ‘<br>’ . $pass;
        echo ‘<bt>’ . $phone;
        echo ‘<br>’ . $address;
        echo ‘<br>’ . $email;
       
    }

}

?>
That it’s you have made a simple enter and display blog using PHP. In the next class, we’ll store the data entered in a Mysql database and manipulate it.

You can find part 2 Here.
If you want to learn to create your own database where you can store user information or any other information, goto- Creating a Database using Xampp.

Any problems? feel free to comment below. I will try my best to answer you.

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

You’ve been successfully subscribed to our newsletter! See you on the other side!

Sharing is caring!

Leave a Comment

Your email address will not be published.

Exit mobile version