Relocate NPC's
#3

Simple PHP script. Call it in browser with param 


cid


(= a_index of your t_characters row) to see values on refresh.



 


<?php



$host = "localhost";



$db = 'db';



$user = 'USER';



$pass = 'password';



$charset = 'utf8mb4';

 


try {



    $pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);



} catch (\PDOException $e) {



    throw new \PDOException($e->getMessage(), (int)$e->getCode());



}

 


// Check for 'cid' in the URL



$cid = isset($_GET['cid']) ? $_GET['cid'] : null;



$data = null;

 


if ($cid) {



    // Prepare and execute the query



    $stmt = $pdo->prepare("SELECT a_nick, a_was_x, a_was_z, a_was_r, a_was_h FROM t_characters WHERE a_datestamp >= NOW() - INTERVAL 48 HOUR AND a_index = ?");



    $stmt->execute([$cid]);



    $data = $stmt->fetch(PDO::FETCH_ASSOC);



}



?>

 


<!doctype html>



<html lang="en">



<head>



    <!-- Bootstrap CSS -->



    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">



    <title>Character Form</title>



</head>



<body>



<div class="container">



    <?php if (!$cid? ?>



        <!-- Form to submit 'cid' -->



        <form action="" method="get">



            <div class="mb-3">



                <label for="cid" class="form-label">Character ID</label>



                <input type="text" class="form-control" id="cid" name="cid" required>



            </div>



            <button type="submit" class="btn btn-primary">Submit</button>



        </form>



    <?php else: ?>



        <!-- New form populated with data if available -->



        <form>



            <input type="hidden" name="cid" value="<?= htmlspecialchars($cid) ?>">



            <div class="mb-3">



                <label for="a_pos_x" class="form-label">Nick</label>



                <input type="text" class="form-control" id="a_nick" name="a_nick" value="<?= htmlspecialchars($data['a_nick'] ?? '') ?>">



                <label for="a_pos_x" class="form-label">Position X</label>



                <input type="text" class="form-control" id="a_pos_x" name="a_pos_x" value="<?= htmlspecialchars($data['a_was_x'] ?? '') ?>">



                <label for="a_pos_x" class="form-label">Position Z</label>



                <input type="text" class="form-control" id="a_pos_z" name="a_pos_z" value="<?= htmlspecialchars($data['a_was_z'] ?? '') ?>">



                <label for="a_pos_x" class="form-label">Position H</label>



                <input type="text" class="form-control" id="a_pos_h" name="a_pos_h" value="<?= htmlspecialchars($data['a_was_h'] ?? '') ?>">



                <label for="a_pos_x" class="form-label">Position R</label>



                <input type="text" class="form-control" id="a_pos_r" name="a_pos_r" value="<?= htmlspecialchars($data['a_was_r'] ?? '') ?>">



            </div>



        </form>



    <?php endif; ?>



</div>



</body>



</html>




Messages In This Thread
[No subject] - by RGT - 02-26-2023, 09:57 PM
[No subject] - by Judgement - 11-16-2023, 06:50 PM
[No subject] - by Judgement - 11-17-2023, 08:10 PM
[No subject] - by RGT - 11-18-2023, 10:01 PM
[No subject] - by Scura - 11-29-2023, 11:19 AM
[No subject] - by Judgement - 11-29-2023, 11:27 AM
[No subject] - by Scura - 01-12-2024, 12:34 PM
[No subject] - by Judgement - 01-12-2024, 01:43 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)