Web Technologies - Old Questions

1.  Develop a simple website that asks the users to register using username, password, and email address. Store these information’s in a database. Use client side script to validate the user input during registration.

10 marks | Asked in 2071-II


<!DOCTYPE html>



    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Form Registration</title>



    <h2>Client Side Form Validation</h2>

    <form name="signupForm" onsubmit="return validateForm();" method="POST" action="./formSubmit.php">


            <label for="username">Please enter your username: </label>

            <input type="text" name="username" id="username">



            <label for="password">Please enter your password: </label>

            <input type="password" name="password" id="password">



            <label for="email">Please enter your email: </label>

            <input type="email" name="email" id="email">



            <input type="submit" name="signup" value="Signup">




        function validateForm() {

            if (document.signupForm.username.value == "") {

                alert("Please provide your usernamename!");


                return false;


            else if (document.signupForm.password.value == "") {

                alert("Please provide your password!");


                return false;


          else if (document.signupForm.password.value.length < 8) {

                alert('Password must be at least 8 digit long');


                return false;


            else if (document.signupForm.email.value == "") {

                alert("Please provide your Email!");


                return false;


            return true;







$servername = "localhost";

$username = "root";

$password = "";

$dbname = "webtech";

$tablename = "users";


$username = $_POST['username'];

$password = $_POST['password'];

        $email = $_POST['email'];

//connect to database

$conn = mysqli_connect($servername, $username, $password) or die(mysql_error()); //Connect to server

mysqli_select_db($conn, $dbname) or die("Cannot connect to database"); //Connect to database

        // Insert the values into database

mysqli_query($conn, "INSERT INTO ".$tablename."(username, password, email) VALUES ('$username','$password', '$email')"); 

Print '<script>alert("Congrats! Your Submission is Successfully Registered!");</script>';