Front Form For User Registration

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Front-end Form for User Registration

<html>
<body>
<h1>User Registration Form</h1>
<form method="POST" action="formData.php">
<label>Name</label> <input type="text" name="UserName" value="Ali Khan"
placeholder="Enter Name" >
<br>
<label>Email</label><input type="email" name="UserEmail"
placeholder="name@domain.com" >
<br>
<label>Password</label> <input type="password" name="UserPassword" ><br>
<label>Gender</label>
Male<input type="radio" name="gender" value="male" >
Female<input type="radio" name="gender" value="female">
<br>
User Pic <input type="file" name="UserPic" >
<br>

<input type="submit" value="Sign up">


<input type="reset" value="Clear">
</form>
</body>
</html>

Server-Side PHP Script

<?php
//Step-01 Database Connection
$host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'web';

$db_connection = mysqli_connect($host, $db_user, $db_pass, $db_name);


if($db_connection){
echo 'DB_CONNECTED';
}
else{
echo 'CONNECTION_FAILED';
}
//Step-02: Fetching Data from HTML FORM
$UserName = $_POST['UserName'];
$UserEmail = $_POST['UserEmail'];
$UserPassword = $_POST['UserPassword'];
$UserGender = $_POST['gender'];

// File Uploading (Move File into files folder & Save path into DB)
$fileName = $_FILES['UserPic']['name'];
$fileTmpPath = $_FILES['UserPic']['tmp_name'];
$fileSize = $_FILES['UserPic']['size'];
move_uploaded_file($fileTmpPath, 'files/'.$fileName);
$SavePicPath = 'files/'.$fileName;

//Step-04 SAVE Data into Table + User Pic Path (users)


if($fileSize > 10000000) // 1.25 MB File Size Limit
{
move_uploaded_file($fileTmpPath, 'files/'.$fileName);
$SavePicPath = 'files/'.$fileName;
//Step-04 SAVE Data into Table + User Pic Path (users)
$qry = "INSERT INTO users (UserName, UserEmail, UserPassword, UserGender, UserPic) VALUES
('$UserName', '$UserEmail' , '$UserPassword', '$UserGender' , '$SavePicPath')";
$results = mysqli_query($db_connection, $qry);

if(!$results){
echo mysqli_error($db_connection);
}
else{
echo 'DATA SAVED';
}
}
?>

DB Table Structure

You might also like