I am trying to save the input
from a PHP
form onto the action page.
So for example, the form is on /world/play/create/create.php
, and onsubmit leads to /world/play/create/index.php?id=(6DIGIT#)
the input of the username from the first URL would be echoed onto the action and saved to the page, so that any user can go back and see it.
However, when I run this code (below), it displays the username on the tab that submitted the form, but other users that go to the link can't see that username when they join; each person can only see their own username.
I'm trying to make it so that each person can see theirs input AND everyone else's, but right now it only shows their own.
Currently this is what I have so far:
The URL:
/world/play/create/index.php?id=M12345
The form (on first link):
<form id="access" method="post" action="/world/play/create/index.php?id=" onsubmit="this.action=this.action.split('#')[0]+'M'+(Math.floor(Math.random()*(75800-39408))+30938);phpValue();">
<input autocomplete="off" type="text" name="nameP1" id="unm" placeholder="Username" value="<?php echo $nameP1;?>">
<br>
<div style="line-height:10px"> </div>
<input type="submit" value="CONTINUE" onclick="return checkInput()">
</form>
The PHP (on second link):
<?php
$nameErr = "";
$nameP1 = "";$nameP2 = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["nameP1"])) {
$nameErr = "Name is required";
} else {
$nameP1 = test_input($_POST["nameP1"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$nameP1)) {
$nameErr = "Only letters and white space allowed";
}
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["nameP2"])) {
$nameErr = "Name is required";
} else {
$nameP2 = test_input($_POST["nameP2"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$nameP2)) {
$nameErr = "Only letters and white space allowed";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
And finally, the PHP echo (on second link):
<span id="playerName"><?php echo $nameP1; ?></span>