prepared语句停止写入mysql表

quhf5bfb  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(291)

该脚本工作了大约6个月,但突然停止了对mysql中3个表之一的写入。我对此束手无策,似乎无法解决这个问题。脚本会写入client_许可证和clients_notes表,但在其生命周期内不会写入clients表。正如我所说的,直到两周前,它都工作得很好。代码没有任何更改,我似乎在db上找不到任何问题。

<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
    header('Location: index.html');
    exit();
}
if( $_SESSION['access'] != "admin") {
    session_destroy();
    header("location: index.html");
}
?>
<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = '***';
$DATABASE_PASS = '***';
$DATABASE_NAME = '***';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if (!isset($_POST['clients_initials'], $_POST['clients_name'], $_POST['clients_nickname'], $_POST['clients_surname'], $_POST['clients_id_nr'], $_POST['clients_profession'], $_POST['clients_tel'], $_POST['clients_tel_alt'], $_POST['clients_email'], $_POST['clients_address_complex'], $_POST['clients_address'], $_POST['clients_suburb'], $_POST['clients_town'], $_POST['clients_province'], $_POST['client_license_nr'], $_POST['client_license_expiry'], $_POST['client_license_code'])) {
    header("Location: statusclient1a_admin.php");
    die();
}
if ($stmt = $con->prepare('SELECT * FROM clients WHERE clients_id_nr = ?')) {
    $stmt->bind_param('s', $_POST['clients_id_nr']);
    $stmt->execute();
    $stmt->store_result();
    if ($stmt->num_rows > 0) {
    header("Location: statusclient2a_admin.php");
    die();
    } else 
    {
if ($stmt = $con->prepare('INSERT INTO clients (clients_initials, clients_name, clients_nickname, clients_surname, clients_id_nr, clients_profession, clients_address, clients_suburb, clients_town, clients_province, clients_tel, clients_email, clients_tel_alt, clients_address_complex, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')) {
    $stmt->bind_param('sssssssssssssss',$_POST['clients_initials'], $_POST['clients_name'], $_POST['clients_nickname'], $_POST['clients_surname'], $_POST['clients_id_nr'], $_POST['clients_profession'], $_POST['clients_address'], $_POST['clients_suburb'], $_POST['clients_town'], $_POST['clients_province'], $_POST['clients_tel'], $_POST['clients_email'], $_POST['clients_tel_alt'], $_POST['clients_address_complex'], $_SESSION['user_id']);
    $stmt->execute();
    $GET_last_ID = mysqli_insert_id($con);
    $url = 'addvehicle_admin.php?id=' . $GET_last_ID;
        header("Location: $url");
} else {
    header("Location: statusclient3a_admin.php");
    die();
}
    }
    if ($stmt1 = $con->prepare('INSERT INTO client_license (clients_id, client_license_nr, client_license_expiry, client_license_code, user_id) VALUES (?, ?, ?, ?, ?)')) {
    $stmt1->bind_param('sssss',$GET_last_ID, $_POST['client_license_nr'], $_POST['client_license_expiry'], $_POST['client_license_code'], $_SESSION['user_id']);
    $stmt1->execute();
    $stmt1->close();
    }
    if ($stmt2 = $con->prepare('INSERT INTO client_notes (clients_id, client_notes_data, user_id) VALUES (?, ?, ?)')) {
    $stmt2->bind_param('sss',$GET_last_ID, $created, $_SESSION['user_id']);
    $created = "Client added to database";
    $stmt2->execute();
    $stmt2->close();
    }   
} else {
    header("Location: statusclient4a_admin.php");
    die();
}
$con->close();
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题