Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function preview(input){
- if(input.files && input.files[0]){
- var reader = new FileReader();
- reader.onload = function(e){
- $('#show')
- .attr('src', e.target.result)
- .width(200)
- .height(200);
- }
- reader.readAsDataURL(input.files[0]);
- }
- }
- $("#prof_pic").change(function(){
- preview(this);
- });
- $(document).ready(function(e) {
- $('.err').hide();
- $('#add_student').submit(function(e) {
- e.preventDefault();
- $('.err').hide();
- prof_pic = $('#prof_pic')[0].files[0];
- name = $('#name').val();
- pName = $('#pName').val();
- month = $('#month').val();
- day = $('#day').val();
- year = $('#year').val();
- date = month + '/' + day +'/' + year;
- level = $('#class').val();
- reg_num = $('#reg_num').val();
- username = $('#username').val();
- pass1 = $('#pass1').val();
- pass2 = $('#pass2').val();
- pass = '';
- if(name == ''){
- $('#n_err').fadeIn();
- $('#name').focus();
- return false;
- }
- if(pName == ''){
- $('#pn_err').fadeIn();
- $('#pName').focus();
- return false;
- }
- if (month == "Month") {
- $('#month').css('border-color','red');
- $('#month').focus();
- return false;
- }
- if (day == "Day") {
- $('#day').css('border-color','red');
- $('#day').focus();
- return false;
- }
- if (year == "Year") {
- $('#year').css('border-color','red');
- $('#year').focus();
- return false;
- }
- if (level == 'Class') {
- $('#class').css('border-color','red');
- $('#class').focus();
- return false;
- }
- if (reg_num == '') {
- $('#reg_num').css('border-color','red');
- $('#reg_num').focus();
- return false;
- }
- if(username == ''){
- $('#user_err').fadeIn();
- $('#username').focus();
- return false;
- }
- if (pass1 == '') {
- $('#pass1_err').fadeIn();
- $('#pass1').focus();
- return false;
- }
- if (pass1 != pass2) {
- $('#pmis_err').fadeIn();
- $('#pass1').focus();
- return false;
- }
- else{
- pass = pass1;
- }
- var student = new FormData();
- student.append('prof_pic',prof_pic);
- student.append('name',name);
- student.append('pName',pName);
- student.append('month',month);
- student.append('day',day);
- student.append('year',year);
- student.append('level',level);
- student.append('reg_num',reg_num);
- student.append('username',username);
- student.append('pass',pass);
- $.ajax({
- type : 'POST',
- url : 'student_process.php',
- data : student,
- processData: false,
- contentType: false,
- success: function(response){
- if(response == 'inserted'){
- window.alert("Student's Info Inserted into Database" );
- }
- else{
- window.alert("Oops! Students data Could Not be Inserted");
- }
- }
- })
- });
- });
- </script>
- <?php
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- include('config.php');
- $conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD,'users');
- $prof_pic = $_FILES['prof_pic']['name'];
- $temp_prof_pic = $_FILES['prof_pic']['tmp_name'];
- $folder = '../pics/students';
- $prof_pic_dir = $folder.'/'.$prof_pic;
- $upload = move_uploaded_file($temp_prof_pic, $prof_pic_dir);
- $name = test_input($_POST['name']);
- $pName = test_input($_POST['pName']);
- $month = $_POST['month'];
- $day = $_POST['day'];
- $year = $_POST['year'];
- $date = $month." ".$day." ".$year;
- $class = $_POST['level'];
- $reg_num = $_POST['reg_num'];
- $reg_num = "GKQC".$reg_num;
- $username = test_input($_POST['username']);
- $password = test_input($_POST['pass']);
- $enc_password = hash("sha512",$password);
- $insert = mysqli_query($conn,"INSERT INTO student (name, parent_name, dob, class, reg_num, prof_pic, username, password) VALUES ('$name', '$pName', '$date', '$class','$reg_num','$prof_pic_dir', '$username', '$enc_password')");
- if ($upload && $insert) {
- echo "inserted";
- }
- else{
- echo "error";;
- }
- mysqli_close($conn);
Add Comment
Please, Sign In to add comment