コード例 #1
0
ファイル: functions.php プロジェクト: NUTV/nutvca
function validate_contest_submission($post_arr)
{
    $errors = array();
    if (false == validateText($post_arr['name'])) {
        $errors['name'] = 'Please enter a valid name.';
    }
    if (false == validateEmail($post_arr['email'])) {
        $errors['email'] = 'Please enter a valid email.';
    }
    if (false == validateText($post_arr['entry-textarea'])) {
        $errors['entry-textarea'] = 'Please enter a valid reason.';
    }
    if (false == isset($post_arr['student']) || false == validateStudent($post_arr['student'])) {
        $errors['student'] = 'Please choose yes or no.';
    }
    if ($post_arr['student'] == 'yes' && false == validateText($post_arr['student-id'])) {
        $errors['student-id'] = 'Please enter a valid student id.';
    }
    if (false == isset($post_arr['confirmation'])) {
        $errors['confirmation'] = 'Please confirm.';
    }
    return count($errors) == 0 ? true : $errors;
}
コード例 #2
0
<?php

if (isset($_POST['add_student'])) {
    $reg_no = $_POST['reg_no'];
    $full_name = $_POST['full_name'];
    $pursuing_course = "";
    $phonenumber = $_POST['phonenumber'];
    $email = $_POST['email'];
    $student_category = $_POST['student_category'];
    $campus_id = $_POST['campus'];
    $faculty_id = $_POST['faculty'];
    $department_id = $_POST['department'];
    $course_id = $_POST['course'];
    $student_adm_yr = $_POST['student_adm_yr'];
    $pursuing_course = $course_id;
    if (validateStudent($campus_id, $faculty_id, $department_id, $course_id, $student_adm_yr, $reg_no, $full_name, $pursuing_course, $phonenumber, $email, $student_category)) {
        $query = "insert into students values ('{$reg_no}','{$full_name}','{$pursuing_course}','{$department_id}','{$phonenumber}','{$email}','{$student_category}','{$student_adm_yr}','{$faculty_id}','{$campus_id}');";
        include 'db_auth.php';
        if (mysqli_query($conn, $query)) {
            increaseCommits("commits", "students");
            echo "Student added successfully<br />";
        } else {
            echo '<span style="color:#FF0000;">Error. Student could not be added.</span><br />';
        }
    }
} else {
    echo "NOT SET";
}
function validateStudent($campus_id, $faculty_id, $department_id, $course_id, $student_adm_yr, $reg_no, $full_name, $pursuing_course, $phonenumber, $email, $student_category)
{
    $form_filled = true;