Student Registration Code in Php


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

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

    <title>Register</title>

    <style>

    fieldset{

        background:aqua;


    }

    h1{

        color:blue;

    }

    legend{

        color:blue; 

        font-size:25px; 

    }

    a{

        font-size:28px;

        text-decoration:none;


        

        

    }

    a:hover{

        background:yellow;

    }

    

    </style>

</head>

<body><center>

<a href="show.php">Show data</a>

    <h1>Registration Form</h1>

    

    <form action="rgcode.php?/=<?php echo basename($_SERVER['PHP_SELF'])?>" method="POST" enctype="multipart/form-data">

    <fieldset style="width:40%">

    <legend>Register Here</legend>

    <p>Name:

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

    </p>

    

    <p>

    Father Name:

    <input type="text" name="fname">

    </p>

    

    <p>

    Mobile Number:

    <input type="number" name="mobile">

    </p>


    <p>

    Email:

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

    </p>


    <p>

    Password:

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

    </p>


    <p>

    Course:

    10th:<input type="checkbox" value="10th" name="course1[]">

    12th:<input type="checkbox" value="12th" name="course1[]">

    Diploma<input type="checkbox" value="Diploma" name="course1[]">

    </p>


    <p>

    Gender:

    Male<input type="radio" name="gender" value="male" >

    Female<input type="radio" name="gender" value="female">

    </p>


    <p>File Upload:

    <input type="file" name="file">

    </p>

    <input type="submit" name="submit"  value="Submit">

   

    </fieldset>

    </form>

    </center>

</body>

</html>


Registration Code in Php




regcode.php

<?php
include 'dbconnect.php';
if($_SERVER['REQUEST_METHOD']=='POST'){
    if(isset($_POST['submit']) and !empty($_POST['submit'])){

        $name=isset($_POST['name'])?$_POST['name']:NULL;

        if(is_null($name) or empty($name)){
            header("location:{$_REQUEST['/']}?action=name&msg=blank-name");
            exit;
        }

        $fname=isset($_POST['fname'])?$_POST['fname']:NULL;

        if(is_null($fname) or empty($fname)){
            header("location:{$_REQUEST['/']}?action=father&msg=blank-father-name");
            exit;
        }

        $email=isset($_POST['email'])?$_POST['email']:NULL;

        if(is_null($email) or empty($email)){
            header("location:{$_REQUEST['/']}?action=email&msg=blank-email");
            exit;
        }

        $password=isset($_POST['password'])?$_POST['password']:NULL;

        if(is_null($password) or empty($password)){
            header("location:{$_REQUEST['/']}?action=password&msg=blank-password");
            exit;
        }

        $mobile=isset($_POST['mobile'])?$_POST['mobile']:NULL;

        if(is_null($mobile) or empty($mobile)){
            header("location:{$_REQUEST['/']}?action=mobile&msg=blank-mobile");
            exit;
        }
        $mobile=isset($_POST['mobile'])?$_POST['mobile']:NULL;

        if(is_null($mobile) or empty($mobile)){
            header("location:{$_REQUEST['/']}?action=mobile&msg=blank-mobile");
            exit;
        }

        $course1=isset($_POST['course1'])?$_POST['course1']:NULL;

        if(is_null( $course1) or empty( $course1)){
            header("location:{$_REQUEST['/']}?action=course&msg=blank-course");
       
        exit;

        }
        $course = implode(",",$course1);
        $mobile=isset($_POST['mobile'])?$_POST['mobile']:NULL;

        if(is_null($mobile) or empty($mobile)){
            header("location:{$_REQUEST['/']}?action=mobile&msg=blank-mobile");
            exit;
        }

        $gender=isset($_POST['gender'])?$_POST['gender']:NULL;

        if(is_null($gender) or empty($gender)){
            header("location:{$_REQUEST['/']}?action=gender&msg=blank-gender");
            exit;
        }


        $file=isset($_FILES['file'])?$_FILES['file']:NULL;
        $file_name = $file['name'];
        if(is_null($file_name) or empty($file_name)){
            header("location:{$_REQUEST['/']}?action=file&msg=blank-file");
            exit;
        }


        $insertquery="insert into tbl_user(Name,Father,Mobile,Email,Password,Course,Gender,File) values('$name','$fname','$mobile','$email',
        '$password','$course','$gender','$file_name')";
        
        $iquery=mysqli_query($con,$insertquery);
        
        if($iquery){

            ?>
            <script>
            window.alert("registration successfully");
            window.location.href="register.php";
            </script>

            <?php

        }else{
            ?>
                <script>
                window.alert("registration failed");
                window.location.href="register.php";
                </script>

            <?php
        }

        
    }else{
        header("location:{$_REQUEST['/']}");
    }

}else{
    header("location:register.php");
}

Registration Code in Php