Hi there! I have here a simple registration code that uses bootstrap to enhance the interface or let’s say to easily create a webpage. This code will allow you to register users in your system by providing an interface for them to fill up necessary data in your system. The same function when you are going to sign up on different sites like facebook, yahoo, google, etc.
The data gathered in this simple registration form program will be used for future purposes such as logging in the system, and accessing those data provided earlier to be displayed in your profile.
The program is also capable of uploading picture and saving it in the dist/img/ directory. If no picture is selected, it will save the default picture which is the default.gif. You can reuse the code later on for your future projects related to PHP and MySQL.
Registration Form Sample output using PHP and MySQL
index page |
Registration Page |
Click the register link on the index page to be able to register to the system.
PHP CODE
<?php
$con = mysqli_connect("localhost","root","","register");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$salut = $_POST['tsalut'];
$last = $_POST['tlast'];
$first = $_POST['tfirst'];
$pass = $_POST['tpass'];
$user = $_POST['tuser'];
$name = $_FILES["timage"]["name"];
if ($name=="")
{
$name="default.gif";
}
else
{
$name = $_FILES["timage"]["name"];
$type = $_FILES["timage"]["type"];
$size = $_FILES["timage"]["size"];
$temp = $_FILES["timage"]["tmp_name"];
$error = $_FILES["timage"]["error"];
if ($error > 0){
die("Error uploading file! Code $error.");
}
else{
if($size > 100000000000) //conditions for the file
{
die("Format is not allowed or file size is too big!");
}
else
{
move_uploaded_file($temp, "../dist/img/".$name);
}
}
}
mysqli_query($con,"INSERT INTO member(t_last,t_first,t_pass,t_salut,t_pic,t_user) VALUES('$last','$first','$pass','$salut','$name','$user')")or die(mysqli_error());
echo "<script type='text/javascript'>alert('Successfully added new teacher!');</script>";
echo "<script>document.location='../index.php'</script>";
?>
Hope this helps! Good day! ^_^
You can download the file in this page and just follow the instructions below.
Database name: register
Use the sql file provided found inside the db folder under dist/ directory.
No comments:
Post a Comment