Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit'])){
- include 'db.php';
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $username = $_POST['username'];
- $email = $_POST['email'];
- $password = $_POST['password'];
- $passwordconfirm = $_POST['passwordconfirm'];
- $age = $_POST['age'];
- $address = $_POST['address'];
- $gender = $_POST['gender'];
- $course = $_POST['course'];
- $occupation = $_POST['occupation'];
- $user = mysqli_query($conn, "SELECT username from users WHERE username = '$username'");
- $count = mysqli_num_rows($user);
- $email = mysqli_query($conn, "SELECT email from users WHERE email = '$email'");
- $count2 = mysqli_num_rows($email);
- if($firstname =='' || $lastname =='' || $username =='' || $email =='' || $password =='' || $passwordconfirm =='' || $age =='' || $address =='' || $gender =='' || $course =='' || $occupation =='' ){
- echo "Please fill out the fields!";
- }
- else if($password != $passwordconfirm) {
- echo "Password does not match!";
- }
- else if($count != 0){
- echo "Username already exist!";
- }
- else if($count2 != 0){
- echo "Email already taken!";
- }
- else{
- $insert = mysqli_query($conn, "INSERT INTO `users` (`firstname`,`lastname`,`username`,`email`,`password`,`age`,`address`,`gender`,`course`,`occupation`) VALUES ('$firstname','$lastname','$username','$email','$password','$age','$address','$gender','$course','$occupation')");
- $result = mysqli_query($conn, $insert);
- if(!$result){
- echo mysqli_errno();
- }
- else{
- echo "Succesfully Registered!";
- }
- }
- }
- ?>
- <html>
- <head><title>Registration Form</title></head>
- <h1>Sign Up</h1>
- <body>
- <form method="POST" >
- First Name: <input type=text name=firstname pattern="[A-Za-z]+" placeholder="Enter your first name" required /> <br>
- Last Name: <input type=text name=lastname pattern="[A-Za-z]+" placeholder="Enter your last name" required /> <br>
- Username: <input type=text name=username pattern="[A-Za-z0-9]+" placeholder="Enter your username" required /> <br>
- Email: <input name="email" type="email" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$" placeholder="Email*" id="email" required /> <br>
- Password: <input type=password name=password pattern="[A-Za-z0-9]+" placeholder="Enter your password" /> <br>
- Confirm Password: <input type=password name=passwordconfirm pattern="[A-Za-z0-9]+" placeholder="Confirm your password" required /> <br>
- Age: <input type=text name=age pattern="[0-9]+" placeholder="Age" required /> <br>
- Home Address: <input type=text name=address placeholder="Enter your home address" required /> <br>
- Gender: <input type=radio name=gender value=male />Male <input type=radio name=gender value=female />Female <br>
- Course: <select name=course >
- <option>IT</option>
- <option>OM</option>
- <option>MKT</option>
- <option>FM</option>
- </select><br>
- Occupation: <select name=occupation >
- <option>Student</option>
- <option>Employed</option>
- <option>Unemployed</option>
- </select><br>
- <input type=submit name=submit value=submit />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement