I am trying to create a multiplayer game where the host will click a button that generates a unique link. They will then be able to send this link to all of the other players that they want to play with. This will allow the other players to join the same session.
My form looks like this:
<form action="includes/host.inc.php" method="post">
<button type="button" onclick="show()" name="Host">Host</button>
</form>
<div id="share" style="display:none;">
<!-- The text field -->
<input type="text" value="Link..." id="myInput">
<!-- The button used to copy the text -->
<button onclick="myFunction()">Copy text</button>
</div>
You can see the action on the form refers to an external PHP file that is supposed to check whether to see the user has clicked the 'Host' button, and if so generates a random key which will be used as part of the unique link and sent to a database.
At the moment I want it to simply echo the random string generated but I'm not even getting much luck with that.
The code for the php file is below:
<?php
if (isset($_POST['Host'])) {
function generateKey() {
$randStr = uniqid();
return $randStr;
}
echo generateKey();
}
else {
echo "didnt work";
}
After clicking the 'Host' button in the form just nothing happens at all and I'm not sure why?
Here you can see my file structure. I think I'm referring to the external PHP file correctly.
If anyone could help me I'd really appreciate it!