PHP和SQL无法从数据库发送数据

时间:2017-10-05 16:15:40

标签: php html sql database phpmyadmin

尝试检查页面可以提交的变量,但数据无法发送到数据库,已检查过所有内容,我不知道是否遗漏了某些内容。

if($ _ SERVER ['REQUEST_METHOD'] =='POST'){

    $applicant_ilname = $mysqli->real_escape_string($_POST['applicant_ilname']);
    $applicant_ifname = $mysqli->real_escape_string($_POST['applicant_ifname']);
    $applicant_imname = $mysqli->real_escape_string($_POST['applicant_imname']);
    $isingle = $mysqli->real_escape_string($_POST['isingle']);
    $imarried = $mysqli->real_escape_string($_POST['imarried']);
    $iwidow = $mysqli->real_escape_string($_POST['iwidow']);
    $iwidower = $mysqli->real_escape_string($_POST['iwidower']);
    $imale = $mysqli->real_escape_string($_POST['imale']);
    $ifemale = $mysqli->real_escape_string($_POST['ifemale']);
    $initial_age = $mysqli->real_escape_string($_POST['initial_age']);
    $initial_homeaddress = $mysqli->real_escape_string($_POST['initial_homeaddress']);
    $ibMonth = $mysqli->real_escape_string($_POST['ibMonth']);
    $idateDay = $mysqli->real_escape_string($_POST['idateDay']);
    $ibYear = $mysqli->real_escape_string($_POST['ibYear']);
    $ibPlace = $mysqli->real_escape_string($_POST['ibPlace']);
    $aiPurpose = $mysqli->real_escape_string($_POST['aiPurpose']);


    $_SESSION['applicant_ilname'] = $applicant_ilname;
    $_SESSION['applicant_ifname'] = $applicant_ifname;
    $_SESSION['applicant_imname'] = $applicant_imname;
    $_SESSION['isingle'] = $isingle;
    $_SESSION['imarried'] = $imarried;
    $_SESSION['iwidow'] = $iwidow;
    $_SESSION['iwidower'] = $iwidower;
    $_SESSION['imale'] = $imale;
    $_SESSION['ifemale'] = $ifemale;
    $_SESSION['initial_age'] = $initial_age;
    $_SESSION['ibMonth'] = $ibMonth;
    $_SESSION['idateDay'] = $idateDay;
    $_SESSION['ibYear'] = $ibYear;
    $_SESSION['ibPlace'] = $ibPlace;
    $_SESSION['aiPurpose'] = $aiPurpose;


    $sql = "INSERT INTO initialform (applicant_ilname, applicant_ifname, applicant_imname, isingle, imarried, iwidow, iwidower, imale, ifemale, initial_age, ibMonth, idateDay, ibYear, ibPlace, aiPurpose)" ."VALUES('$applicant_ilname', '$applicant_ifname', '$applicant_imname', '$isingle', '$imarried', '$iwidow', '$iwidower', '$imale', '$ifemale', '$initial_age', '$ibMonth', '$idateDay', '$ibYear', '$ibPlace', '$ibPlace', '$aiPurpose')";


  }


?>

1 个答案:

答案 0 :(得分:0)

您错过了查询的“执行”部分。

在$ sql = add:

之后的文件末尾
mysqli_query($conn, $sql);

其中$ conn是配置数据库连接的var。

还要记住,尽管$ mysqli-> real_escape_string是一件好事,但您必须验证您的数据,否则您可能会尝试将空值或字符串值插入错误的字段。

尝试使用 prepared statements catch the error