I have been experimenting with this code:
<html>
<head>
<title>Test</title>
<h3>Test</h3>
</head>
<body>
<?php
$name = $_POST["name"];
$age = $_POST["age"];
$con = new mysqli("localhost","root","","server");
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT * FROM `joinedplayers`";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["num"]. " - Name: " . $row["name"]. " - Age: " . $row["age"]. " <button type = 'button'> Get Info </button> <br><br>";
}
} else {
echo "0 results";
}
$con->close();
?>
</body>
</html>
Btw: I'm using XAMPP and phpMyAdmin
For some reason, I can't send requests to the script. I have a table that holds 3 values: the current number (first-person = 1, second-person = 2 and so on...) the name (varchar) and an age value which holds an int. If I run this, without the two lines with $_POST
, it works fine and lists all the objects in the table as I want it too. Also, the MySQLI is connecting to the localhost just fine. Is there any way to get the values sent as a post and add them to the database?
Also, here is the code I used inside of Fiddler 4: name=test&age=5