I am trying to send post request to my SQL database via PHP when user clicks on canvas.
I am stuck on this for a few days and tried a lot of solutions from internet but none of the worked. There’s not much code that I have, but here’s my post request
$sendData = "send me";
$conn = new mysqli('localhost','root','','database');
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ". $conn->connect_error);
} else {
$stmt = $conn->prepare("INSERT INTO table(data) values(?)");
$stmt->bind_param("s", $sendData);
$execval = $stmt->execute();
echo $execval;
echo "Nice";
$stmt->close();
$conn->close();
}
I don’t want to do post request in JS (inside <script>
) because as I am informed users can see code inside <script>
and can’t see it inside <?php ?>