Now you can Subscribe using RSS

Submit your Email


Your first PHP enabled page(Sign Up from-part 1)

Vishal Shrestha
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.

<title>Sign Up</title>
<? 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.
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.
      // Pointing to the signup function of the User class object stored in $n.

//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">
<td width="27%">Username</td>
<td width="73%"><input type="text" name="username"></td>
<td width="27%">Email</td>
<td width="73%"><input type="text" name="email"></td>
<td width="27%">Address</td>
<td width="73%"><input type="text" name="address"></td>
<td width="27%">Phone</td>
<td width="73%"><input type="text" name="phone"></td>
<td><input type="password" name="password"></td>
<td><input type="submit" name="submit" value="Submit"></td>


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.

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.

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)

For Business info : My Portfolio Site.


Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha