connect_error) { die("Connection failed: " . $conn->connect_error); } //Check for existing game from this IP. $stmt = $conn->stmt_init(); $stmt->prepare( "SELECT ID " . "FROM StartedGame " . "WHERE IPAddr = ? " . "AND ID NOT IN " . " (SELECT ID " . " FROM CompletedGame " . " WHERE IPAddr = ?)"); $stmt->bind_param("ss", $playerIP, $playerIP); $stmt->execute(); $dbresult = $stmt->get_result(); if ($dbresult->num_rows > 0) { //Found existing incomplete game. $row = $dbresult->fetch_assoc(); $playerid = $row["ID"]; $stmt->close(); $gameexists = true; } else { //No existing game, so create a new game. $stmt->close(); $gameexists = false; $stmt = $conn->stmt_init(); $stmt->prepare( "INSERT INTO StartedGame (IPAddr) " . "VALUES (?)"); $stmt->bind_param("s", $playerIP); $stmt->execute(); $playerid = $stmt->insert_id; $stmt->close(); } if ($gameexists) { //Continue existing game echo "

Welcome back! You may continue on your quest.

"; $buttontext = "Continue"; } else { //Load the intro from the database $stmt = $conn->stmt_init(); $stmt->prepare( "SELECT Text " . "FROM Question " . "WHERE Name = 'INTRO' "); $stmt->execute(); $dbresult = $stmt->get_result(); if ($dbresult->num_rows > 0) { $row = $dbresult->fetch_assoc(); $introText = $row["Text"]; } else { die("Error in database: missing INTRO text."); } //Display the introductory text echo "

" . $introText . "

"; $buttontext = "Start your quest!"; } $conn->close(); //Display a form to start the next question ?>