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

0
6761

This tutorial is all about 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 &lt;br ?--> //set up mysql connection
  2. mysql_connect("localhost", "root", "") or die(mysql_error());
  3. //select database
  4. mysql_select_db("studentdb") or die(mysql_error());
  5.  
  6. $fName = $_POST['fName'];
  7. $lName = $_POST['lName'];
  8. $email = $_POST['email'];
  9. $reemail = $_POST['reemail'];
  10. $password = sha1($_POST['password']);
  11. $month = $_POST['month'];
  12. $day = $_POST['day'];
  13. $year = $_POST['year'];
  14. $gender = $_POST['optionsRadios'];
  15. $birthdate = $year . '-' . $month . '-' . $day;
  16.  
  17. $query = "INSERT INTO tblmember(id, fName, lName, email, password, birthdate, gender)
  18. VALUES (NULL, '{$fName}', '{$lName}', '{$email}', '{$password}', '{$birthdate}', '{$gender}')";
  19.  
  20. if (mysql_query($query)) {
  21.  
  22. echo "\"text/javascript\">
  23.                alert(\"New member added successfully.\");
  24.                window.location = \"registration.php\"
  25.            ";
  26.  
  27. } else
  28. die("Failed: " . mysql_error());
  29. ?&gt;

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

 

Readers might read also:

 

 

Facebook Comments
(Visited 984 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here