| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/thelittlebigshow/app.05-08-26/ |
Upload File : |
<?php
session_start();
include_once("db.php");
require_once(__DIR__ . "/phpqrcode/qrlib.php");
/**
* DEBUG / DIAGNOSTIC LOGGING
* These lines write to Apache error log: /var/log/apache2/error.log
*/
error_log("TBS DEBUG: action.php path=" . __FILE__);
error_log("TBS DEBUG: PHP_SAPI=" . php_sapi_name() . " PHP=" . PHP_VERSION .
" GD=" . (extension_loaded('gd') ? "yes" : "no") .
" imagepng=" . (function_exists('imagepng') ? "yes" : "no"));
if (!class_exists('QRcode')) {
die("QR library not loaded (QRcode class missing). Check phpqrcode/qrlib.php path.");
}
// Only run on form submit
if (!isset($_POST["submit"])) {
header("Location: index.php");
exit;
}
// Collect form data
$name = trim($_POST["name"] ?? '');
$address = trim($_POST["address"] ?? '');
$phone = trim($_POST["phone"] ?? '');
$vehicle_maker = trim($_POST["vehicle_maker"] ?? '');
$vehicle_model = trim($_POST["vehicle_model"] ?? '');
$vehicle_year = trim($_POST["vehicle_year"] ?? '');
$category = trim($_POST["category"] ?? '');
$my_date = date("Y-m-d H:i:s");
$checkbox = isset($_POST["checkbox"]) ? "yes" : "no";
// Require only core fields
if ($name === '' || $vehicle_model === '' || $vehicle_year === '' || $category === '' || $category === 'Select Category') {
$_SESSION['msg'] = "Please fill in all required fields (Name, Vehicle Model, Vehicle Year, Category).";
header("Location: index.php");
exit;
}
// Paths
$imagesDir = __DIR__ . "/images/";
$publicQrDir = __DIR__ . "/images/publicQr/";
// Ensure folders exist
if (!is_dir($imagesDir)) {
mkdir($imagesDir, 0755, true);
}
if (!is_dir($publicQrDir)) {
mkdir($publicQrDir, 0755, true);
}
// Log writability
error_log("TBS DEBUG: imagesDir=" . $imagesDir . " writable=" . (is_writable($imagesDir) ? "yes" : "no"));
error_log("TBS DEBUG: publicQrDir=" . $publicQrDir . " writable=" . (is_writable($publicQrDir) ? "yes" : "no"));
// QR filename
$imgTime = time();
$qrFilename = $imgTime . ".png";
// Insert the vehicle first (stores filenames in DB)
$sql = "INSERT INTO vehicles
(name, address, phone, vehicle_maker, vehicle_model, vehicle_year, category, checkbox, qrcode, created_date, fav_qr)
VALUES
('$name','$address','$phone','$vehicle_maker','$vehicle_model','$vehicle_year','$category','$checkbox','$qrFilename','$my_date','$qrFilename')";
if (!mysqli_query($conn, $sql)) {
error_log("TBS DEBUG: DB insert failed: " . mysqli_error($conn));
$_SESSION['msg'] = "Please Try Again!!";
header("Location: index.php");
exit;
}
// Current Inserted ID
$curr_id = mysqli_insert_id($conn);
// Build base URL safely
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
$base_url = $scheme . "://" . $_SERVER['HTTP_HOST'];
// If app is in a subfolder, include that path
$scriptDir = rtrim(str_replace("\\", "/", dirname($_SERVER['SCRIPT_NAME'])), "/");
$base_url .= ($scriptDir !== '') ? $scriptDir . "/" : "/";
// Data for QRs
$privateData = $base_url . "vote.php?id=" . $curr_id; // Little Big Show use only
$publicData = $base_url . "public_vote.php?id=" . $curr_id; // People�s Choice
// Output paths
$privateQrPath = $imagesDir . $qrFilename;
$publicQrPath = $publicQrDir . $qrFilename;
error_log("TBS DEBUG: privateData=" . $privateData);
error_log("TBS DEBUG: publicData=" . $publicData);
error_log("TBS DEBUG: privateQrPath=" . $privateQrPath);
error_log("TBS DEBUG: publicQrPath=" . $publicQrPath);
// Generate private QR
QRcode::png($privateData, $privateQrPath, 'H', 4, 4);
clearstatcache(true, $privateQrPath);
if (!file_exists($privateQrPath)) {
$e = error_get_last();
error_log("TBS DEBUG: private QR NOT created. last_error=" . print_r($e, true));
$_SESSION['msg'] = "Registered, but PRIVATE QR could not be created. Check server logs.";
mysqli_close($conn);
die("Private QR NOT created. Check /var/log/apache2/error.log for 'TBS DEBUG' lines.");
}
// Generate public QR
QRcode::png($publicData, $publicQrPath, 'H', 4, 4);
clearstatcache(true, $publicQrPath);
if (!file_exists($publicQrPath)) {
$e = error_get_last();
error_log("TBS DEBUG: public QR NOT created. last_error=" . print_r($e, true));
$_SESSION['msg'] = "Registered, but PUBLIC QR could not be created. Check server logs.";
mysqli_close($conn);
die("Public QR NOT created. Check /var/log/apache2/error.log for 'TBS DEBUG' lines.");
}
// Done
$_SESSION['msg'] = "Thanks, Your data has been recorded successfully.";
mysqli_close($conn);
// Redirect to printable/view page
header("Location: view.php?id=" . $curr_id);
exit;