The error message I get is:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Player Name', 'Player Age', 'Player Team') VALUES ('Willian', '27', 'Chelsea')' at line 1 in C:\xampp\htdocs\WebProgrammingWebsite\add-player.php:9 Stack trace: #0 C:\xampp\htdocs\WebProgrammingWebsite\add-player.php(9): PDO->prepare('INSERT INTO pla...') #1 {main} thrown in C:\xampp\htdocs\WebProgrammingWebsite\add-player.php on line 9
I have double checked and tried to change what is written on line 9 like it says but I just can't get it to work. I have also tried to use the whole "Bind_param" thing but I'm just a noob and nothing is working. It has to be some dumb syntax mistake on my part but it's driving me crazy Here is my code:
<?php
require("connect.php");
if(isset($_POST['submit'])) {
$name = $_POST['p_name'];
$age = $_POST['p_age'];
$team = $_POST['p_team'];
$stmt = $con->prepare("INSERT INTO player ('Player Name', 'Player Age', 'Player Team') VALUES ('".$name."', '".$age."', '".$team."')");
$stmt->execute();
$stmt->closeCursor();
header("Location: display-players.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Football Database</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<form class="add" action="" method="post">
<label>Player Name</label>
<input type="text" name="p_name"><br>
<label>Player Age</label>
<input type="text" name="p_age"><br>
<label>Player Team</label>
<input type="text" name="p_team"><br>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="resources/js/main.js"></script>
</body>
</html>