Now you can Subscribe using RSS

Submit your Email


Using MySQL database with PHP to Store Sign Up Information tutorial

Vishal Shrestha
Check out part one of creating sign up form.
In the previous class we created a signup form and stored the data in variable and displayed it using echo. Now instead of displaying the data directly, we will store the data in a Mysql database so that we can use the data whenever we need it. Even if you don't have understanding of sql queries, you can easily get along as i will show you just basic operation and if you have any doubts, just comment 'em up.

  To store the sign up data of users in a database, first of all you need a database. You can see how I create local database using XAMPP here.
After creating your database you need to connect to the database just created and then simply modify the signup function that we created in the user class. 
Connet to your database like this-

function __construct() {

        $this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->db);
        if ($this->mysqli->error) {
            echo $this->mysqli->error;
        } else
            echo"connection successful<br>";

    private $host = "localhost";  // default localhost

    private $db = "kathford_db"; //name of the database
    private $user = "root";  // default root
    private $pass = ""; // default password

    private $mysqli;

And then modify the signup function of part 1 like this-

function signup() {

        //echo "hi i am test<br>";
        $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;
        $sql = "insert into tbl_user(name,email,address,phone,password) values('$user','$email','$address','$phone','$pass')";
        if ($this->mysqli->error) {
            echo $this->mysqli->error;
        } else {
            echo "insertion successful";

We are done, very simple, wasn't it? Next we will learn how to sign in a user by checking his email and password, till then, happy coding and if any problems, just comment or connect to me.

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 ;)


Research and Development at : Ekghanti

Mobile Technology Lead at : Vimvox Lab

For Business info : My Portfolio Site


Post a Comment

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