Free Source Code and Tutorials

Custom Search

Saving Data from Registration Form into MySQL Database using PHP/MySQL

Today, im going to show to show you how to Save Data from Registration Form into MYSQL Database using PHP/MySQL. This tutorial is a continuation of our last topic called “How to Create a Registration Page Using a Twitter Bootstrap Framework”. But first, we need to create a new database called “studentdb”. And here’s the table schema used for this application:

  1. CREATE TABLE IF NOT EXISTS `tblmember` (
  2. `fName` varchar(30) NOT NULL,
  3. `lName` varchar(30) NOT NULL,
  4. `email` varchar(50) NOT NULL,
  5. `password` varchar(60) NOT NULL,
  6. `birthdate` text NOT NULL,
  7. `gender` varchar(20) NOT NULL,

At this time, we need to create a new PHP file and save it as “register.php” inside the “snappy” folder. The main purpose of this file is that, when the user click the button after filling up all the fields provided, then all the value from the different fields will be posted into this file for processing the saving of data in the database. And here’s the following code for this newly added php file.

  1. <?php
  2. //set up mysql connection
  3. mysql_connect("localhost", "root", "") or die(mysql_error());
  4. //select database
  5. mysql_select_db("studentdb") or die(mysql_error());
  7. $fName     = $_POST&#91;'fName'];
  8. $lName     = $_POST&#91;'lName'];
  9. $email     = $_POST&#91;'email'];
  10. $reemail   = $_POST&#91;'reemail'];
  11. $password  = sha1($_POST&#91;'password']);
  12. $month     = $_POST&#91;'month'];
  13. $day       = $_POST&#91;'day'];
  14. $year      = $_POST&#91;'year'];
  15. $gender    = $_POST&#91;'optionsRadios'];
  16. $birthdate = $year . '-' . $month . '-' . $day;
  19. $query = "INSERT INTO tblmember(id, fName, lName, email, password, birthdate, gender)
  20.                    VALUES (NULL, '{$fName}', '{$lName}', '{$email}', '{$password}', '{$birthdate}', '{$gender}')";
  22. if (mysql_query($query)) {
  24.     echo "\"text/javascript\">
  25.                alert(\"New member added successfully.\");
  26.                window.location = \"registration.php\"
  27.            ";
  29. } else
  30.     die("Failed: " . mysql_error());
  31. ?>

Then you can now test this application by running it in your browser.

Previous topic:
How to Create a Registration Page Using a Twitter Bootstrap Framework

Next topic:
How to useTwitter Bootstrap Table using PHP/MySQL

Facebook Comments
(Visited 88 times, 4 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: