You will see this type of interface and start Apache and MySQL. After that your localhost will be ready. We have already made the register form in previous article, so I am going to use that form. Note that you have to mention the input method and action in the form as shown below:
After that click on MySQL Admin to open PhpMyadmin.
Create new database. I have created and named as "sampleform"(Note: Please do not leave space between the two words that you named for database). After that create new table to storge your data.
Php Code to connect HTML form to database:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="sampleform"; // Database name
$tbl_name="connectregister"; // Table name
// Connect to server and select database.
$conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db($conn, "$db_name")or die("cannot select DB");
// Get values from form
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$dob=$_POST['dob'];
$gender=$_POST['gender'];
$address=$_POST['address'];
$mnumber=$_POST['mnumber'];
$email=$_POST['email'];
$password=$_POST['password'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(fname, lname, dob, gender, address, mnumber, email, password) VALUES('$fname', '$lname', '$dob', '$gender','$address', '$mnumber', '$email', '$password')";
$result=mysqli_query($conn, $sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Thank You ! Your account registered Successfully! ";
echo "<BR>";
}
else {
echo "ERROR";
}
?>
Now save this code and fill data on register form and submit.
0 Comments