php.css和html undefined index和uncaught exemption

时间:2017-02-26 10:36:01

标签: php

这是我重新加载浏览器后出现的错误(注意:未定义的索引:)以及此问题(未捕获的异常' PDOException'带有消息' SQLSTATE [HY093]:参数号无效:绑定变量的数量与令牌的数量不匹配')

这是我的代码:

addform.php

<input type="text" name="EMPLOYEENO" placeholder="Employee No"> 
    <input type="text" name="NAME" placeholder="Name">
    <input type="text" name="OCCUPATION" placeholder="Occupation">
    <input type="text" name="GENDER" placeholder="Gender"><br><br>
    <input type="text" name="AGE" placeholder="Age">
    <input type="text" name="ADDRESS" placeholder="Address">
    <input type="text" name="CELLPHONE" placeholder="Cellphone No">
    <input type="text" name="DATEOFBIRTH" placeholder="Date of Birth"><br><br>
    <input type="text" name="CITIZEN" placeholder="Citizenship">
    <input type="text" name="RELIGION" placeholder="Religion">
    <input type="text" name="HEIGHT" placeholder="Height">
    <input type="text" name="WEIGHT" placeholder="Weight"><br><br>
    <input type="text" name="ELEMENTARY" placeholder="Elementary">
    <input type="text" name="ELEMENTARYYEAR" placeholder="Year Graduated"><br><br>
    <input type="text" name="HIGHSCHOOL" placeholder="High School">
    <input type="text" name="HIGHYEAR" placeholder="Year Graduated"><br><br>
    <input type="text" name="COLLEGE" placeholder="College">
    <input type="text" name="COLLEGEYEAR" placeholder="Year Graduated"><br>
    <button><a href="addform_process.php">SUBMIT</a></button>
</div>

AND ADDFORM_PROCESS.PHP

$idno = $_POST['EMPLOYEENO'];
$name = $_POST['NAME'];
$occ = $_POST['OCCUPATION'];
$gender = $_POST['GENDER'];
$age = $_POST['AGE'];
$address = $_POST['ADDRESS'];
$cell = $_POST['CELLPHONE'];
$birth = $_POST['DATEOFBIRTH'];
$citizen = $_POST['CITIZEN'];
$religion = $_POST['RELIGION'];
$height = $_POST['HEIGHT'];
$weight = $_POST['WEIGHT'];
$elementary = $_POST['ELEMENTARY'];
$elementaryyear = $_POST['ELEMENTARYYEAR'];
$highschool = $_POST['HIGHSCHOOL'];
$highschoolyear = $_POST['HIGHYEAR'];
$college = $_POST['COLLEGE'];
$collegeyear = $_POST['COLLEGEYEAR'];

if ($idno="" || $name="" || $occ="" || $gender="" || $age="" || $address="" || $cell="" || $birth="" || $citizen="" ||
    $religion="" || $height="" || $weight="" || $elementary="" || $elementaryyear="" || $highschool="" || 
    $highschoolyear="" || $college="" || $collegeyear=""){

    echo "<script>

            alert('Dont leave the textbox empty!');
            window.location='addform.php';

          </script>";

}else{

$stmt=$db->prepare("INSERT INTO tbl_employee_information(EmployeeNo,Name,Occupation,Gender,Age,Address,CellphoneNo,DateofBirth,Citizenship,Religion,Height,Weight,Elementary,YearGraduatedinElementary,HighSchool,YearGraduatedinHighSchool,College,YearGraduatedinCollege) VALUES(:EMPLOYEENO,:NAME,:OCCUPATION,:GENDER,:AGE,:ADDRESS,:CELLPHONE,
        :DATEOFBIRTH,:CITIZEN,:RELIGION,:HEIGHT,:WEIGHT,:ELEMENTARY,:ELEMENTARYYEAR,:HIGHSCHOOL,:HIGHYEAR,:COLLEGE,:
        COLLEGEYEAR)");

    $stmt->bindParam(':EMPLOYEENO',$idno);
    $stmt->bindParam(':NAME',$name);
    $stmt->bindParam(':OCCUPATION',$occ);
    $stmt->bindParam(':GENDER',$gender);
    $stmt->bindParam(':AGE',$age);
    $stmt->bindParam(':ADDRESS',$address);
    $stmt->bindParam(':CELLPHONE',$cell);
    $stmt->bindParam(':DATEOFBIRTH',$birth);
    $stmt->bindParam(':CITIZEN',$citizen);
    $stmt->bindParam(':RELIGION',$religion);
    $stmt->bindParam(':HEIGHT',$height);
    $stmt->bindParam(':WEIGHT',$weight);
    $stmt->bindParam(':ELEMENTARY',$elementary);
    $stmt->bindParam(':ELEMENTARYYEAR',$elementaryyear);
    $stmt->bindParam(':HIGHSCHOOL',$highschool);
    $stmt->bindParam(':HIGHYEAR',$highschoolyear);
    $stmt->bindParam(':COLLEGE',$college);
    $stmt->bindParam(':COLLEGEYEAR',$collegeyear);
    $stmt->execute();
    header("location:main.php");

1 个答案:

答案 0 :(得分:0)

也许如果你把参数的名字放在一个数组中并使用foreach循环来构建你的请求文本和bindParam的多次调用,那么调试会更容易吗?