answer
Question ID: = (int)$newId ?>
Add another question
source_id
answer = 1–4
answer_key
answer_text
answer_key = NULL
Attached to Source ID: = (int)$sourceId ?>
block and reloaded https://chronology.amyjohoward.com/pages/question_form.php?source_id=1459. The browser couldn't load the page. Chrome said: This page isn’t working chronology.amyjohoward.com is currently unable to handle this request. HTTP ERROR 500 ChatGPT said: That 500 happened because your site is configured to hide PHP errors, so my debug snippet triggered a fatal error or your server choked before it could output anything. Either way, we need to get the real error message from the server logs or temporarily enable error display just for this page. Here’s the fastest way to diagnose without guessing. 1) Turn on error reporting at the top of question_form.php (temporary) Put this as the very first thing in the file (literally right after debug block right after it: echo ""; echo "QUERY_STRING: "; var_dump($_SERVER['QUERY_STRING'] ?? null); echo "GET: "; var_dump($_GET); echo ""; exit; Reload the page again. What should happen Instead of a blank 500 page, you’ll see an actual PHP error like: “Call to undefined function …” “Cannot modify header information…” “Failed opening required …/database.php” etc. Copy/paste that error here. 2) The most likely cause of the 500 (based on your setup) On shared hosting, the #1 culprit is a bad include path: require_once __DIR__ . '/../run_code/database.php'; If question_form.php is in /pages/, then ../run_code/database.php points to /run_code/database.php at the web root. If your folder structure is different (common on Hostinger), PHP dies → HTTP 500. Once error display is on, you’ll see something like: failed to open stream: No such file or directory If that’s the error, fix the path to the actual location. Example possibilities: require_once __DIR__ . '/../../run_code/database.php'; or require_once $_SERVER['DOCUMENT_ROOT'] . '/run_code/database.php'; 3) If you don’t want to show errors to the browser (safer) Use Hostinger’s error log: hPanel → Websites → your site → Advanced → Error log Or File Manager → look for error_log in your site directory Reload the page once and then check the log. Paste the newest entry. 4) After you find the error, undo the debug stuff Once we confirm why it’s 500’ing: remove display_errors lines remove the block keep the final logic Do this now Add the 3-line error reporting header and reload. Paste the exact PHP error text that shows up. That will let me give you the exact fix in one shot. You said: Chrome still says this page isn't working. Here is the page code that you wrote: "; echo "QUERY_STRING: "; var_dump($_SERVER['QUERY_STRING'] ?? null); echo "GET: "; var_dump($_GET); echo ""; exit; declare(strict_types=1); require_once __DIR__ . '../run_code/database.php'; session_start(); /* ---------------- CSRF ---------------- */ if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } $csrfToken = $_SESSION['csrf_token']; /* ---------------- source_id from URL ---------------- */ $source_id = isset($_GET['source_id']) ? (int)$_GET['source_id'] : 0; if ($sourceId <= 0 || $sourceId > 65535) { http_response_code(400); exit('Missing or invalid source_id in URL.'); } /* Validate source exists */ $stmt = mysqli_prepare($connection, "SELECT source_id FROM sources WHERE source_id = ? LIMIT 1"); mysqli_stmt_bind_param($stmt, 'i', $sourceId); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); if (mysqli_stmt_num_rows($stmt) !== 1) { mysqli_stmt_close($stmt); http_response_code(404); exit('Source not found.'); } mysqli_stmt_close($stmt); /* ---------------- Load projects ---------------- */ $sql = "SELECT project_id, project_title FROM projects ORDER BY project_title ASC"; $res = mysqli_query($connection, $sql); if (!$res) { http_response_code(500); exit('Could not load projects.'); } $projects = []; while ($row = mysqli_fetch_assoc($res)) { $projects[] = $row; } mysqli_free_result($res); ?> Add Quiz Question Add Quiz Question Attached to Source: = (int)$source_title ?> Project Select a project… = htmlspecialchars($p['project_title']) ?> Question Type Multiple choice Numeric Question Options (tap correct answer) > Numeric Answer Save Question ChatGPT said: You’ve got multiple fatal PHP problems in that file. Any one of them can throw a 500. Here are the big ones, in plain terms, and then I’ll give you a clean fixed full file you can paste in. What’s wrong (the real issues) 1) declare(strict_types=1); is in the wrong place In PHP it must be the first statement in the file (after It’s not defined You’re casting it to int (nonsense) That won’t necessarily fatal, but it’s wrong. 6) Your form action points somewhere else You used: action="../run_code/question_submit.php" But earlier we were using question_submit.php in the same folder as the form. If yours is actually in /run_code/, fine — but then you need to keep paths consistent. ✅ Paste-this fixed version: pages/question_form.php This version: Pulls source_id from URL Validates it exists Fetches source_title to display (optional but helpful) Loads projects using project_title Posts to question_submit.php (same folder as this file). If your submit file is elsewhere, change ONE line. 65535) { http_response_code(400); exit('Missing or invalid source_id in URL.'); } /* ---------------- Validate source + get title ---------------- */ $sourceTitle = ''; $stmt = mysqli_prepare($connection, "SELECT source_title FROM sources WHERE source_id = ? LIMIT 1"); if (!$stmt) { http_response_code(500); exit('DB prepare failed (sources).'); } mysqli_stmt_bind_param($stmt, 'i', $sourceId); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $sourceTitle); if (!mysqli_stmt_fetch($stmt)) { mysqli_stmt_close($stmt); http_response_code(404); exit('Source not found.'); } mysqli_stmt_close($stmt); /* ---------------- Load projects ---------------- */ $res = mysqli_query($connection, "SELECT project_id, project_title FROM projects ORDER BY project_title ASC"); if (!$res) { http_response_code(500); exit('Could not load projects.'); } $projects = []; while ($row = mysqli_fetch_assoc($res)) { $projects[] = $row; } mysqli_free_result($res); ?> Add Quiz Question Add Quiz Question Source ID: = (int)$sourceId ?> Source title: = htmlspecialchars((string)$sourceTitle) ?> Project Select a project… = htmlspecialchars((string)$p['project_title']) ?> Question Type Multiple choice Numeric Question Options (tap correct answer) > Numeric Answer Save Question After you confirm it loads Turn off error display by deleting these three lines (keep the rest): ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); One more thing: your original “query string missing” mystery Once this version loads, it will prove whether $_GET['source_id'] is coming through. If it still says missing, then you truly have a rewrite/QS stripping issue — but right now you’re not even getting that far because the file is fatally broken. If you paste your current question_submit.php location (is it in /pages/ or /run_code/?), I’ll align the action= path and the include paths so you’re not playing whack-a-mole. You said: My database convention is source_id, not camel case. ChatGPT said: Cool — then don’t fight your own convention. Use snake_case in PHP too. That’s totally normal (and honestly cleaner for DB-driven pages). Here’s the same question_form.php rewritten to use $_GET['source_id'] → $source_id everywhere, with the other bugs fixed (proper declare, fixed include path, defined $source_title, and consistent variables). pages/question_form.php (snake_case throughout) 65535) { http_response_code(400); exit('Missing or invalid source_id in URL.'); } /* ---------------- Validate source + get title ---------------- */ $source_title = ''; $stmt = mysqli_prepare($connection, "SELECT source_title FROM sources WHERE source_id = ? LIMIT 1"); if (!$stmt) { http_response_code(500); exit('DB prepare failed (sources).'); } mysqli_stmt_bind_param($stmt, 'i', $source_id); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $source_title); if (!mysqli_stmt_fetch($stmt)) { mysqli_stmt_close($stmt); http_response_code(404); exit('Source not found.'); } mysqli_stmt_close($stmt); /* ---------------- Load projects ---------------- */ $res = mysqli_query($connection, "SELECT project_id, project_title FROM projects ORDER BY project_title ASC"); if (!$res) { http_response_code(500); exit('Could not load projects.'); } $projects = []; while ($row = mysqli_fetch_assoc($res)) { $projects[] = $row; } mysqli_free_result($res); ?> Add Quiz Question Add Quiz Question Source ID: = (int)$source_id ?> Source title: = htmlspecialchars((string)$source_title) ?> Project Select a project… = htmlspecialchars((string)$p['project_title']) ?> Question Type Multiple choice Numeric Question Options (tap correct answer) > Numeric Answer Save Question Two quick notes If your submit script lives in run_code/, set: action="../run_code/question_submit.php" If your database.php path is different, keep using the safe form: require_once __DIR__ . '/../run_code/database.php'; If you want, paste your current question_submit.php location (and filename) and I’ll rewrite that file in snake_case too so everything matches end-to-end.
"; echo "QUERY_STRING: "; var_dump($_SERVER['QUERY_STRING'] ?? null); echo "GET: "; var_dump($_GET); echo "
block keep the final logic Do this now Add the 3-line error reporting header and reload. Paste the exact PHP error text that shows up. That will let me give you the exact fix in one shot. You said: Chrome still says this page isn't working. Here is the page code that you wrote: "; echo "QUERY_STRING: "; var_dump($_SERVER['QUERY_STRING'] ?? null); echo "GET: "; var_dump($_GET); echo "
Attached to Source: = (int)$source_title ?>
Source ID: = (int)$sourceId ?>
Source title: = htmlspecialchars((string)$sourceTitle) ?>
Source ID: = (int)$source_id ?>
Source title: = htmlspecialchars((string)$source_title) ?>