The script worked for roughly 6 months but then suddenly stopped writing to one of the 3 tables in MySQL. Script writes to the client_license and clients_notes tables but wont for the life of it write to the clients table. As I say it did work perfectly up until 2 weeks ago. Nothing changed to the code and I can't seem to find any issues on the 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();
?>