For school we have to make a simple database and a page from where people can fill in their details and to send them to a database to later recall them on a different page.
For this i created a simple html form where people can fill in the details to be send yet when i press submit i get:
Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Begintime', 'Instructor', 'Players', 'Gamename') VALUES ('','','','')'"
i'm also getting some data from a different database provided by school(so it works perfectly thank god) which is $sql1
so its for sure somewhere there but i can't seem to figure out what at this point. Hopefully somebody sees what i can't see.
i'm relatively new to php and mysql and still on school but it's vacation now so i am unable to find help on school since it's closed
<?php
$servername = "localhost";
$username = "root";
$password = "mysql";
$dbname = "Planningstool";
$Begintime = $_POST["Begintime"];
$Instructor = $_POST["Instructor"];
$Players = $_POST["Players"];
$Gamename = $_POST["Gamename"];
$conn = new PDO("mysql:host=$servername;dbname=Planningstool", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$stmt = $conn->prepare("INSERT INTO Planning ('Begintime', 'Instructor', 'Players', 'Gamename') VALUES (:Begintime,:Instructor,:Players,:Gamename)");
$stmt->bindParam(':Begintime', $Begintime);
$stmt->bindParam(':Instructor', $Instructor);
$stmt->bindParam(':Players', $Players);
$stmt->bindParam(':Gamename', $Gamename);
$stmt->execute();
header("somewhere")
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
}
$sql1 = "SELECT id, name, image, description, expansions, skills, url, youtube, min_players, max_players, play_minutes, explain_minutes FROM games";
$result = $conn->query($sql1);
$row = $result->fetch();
$dbresult = $conn->prepare($sql2);
<div>
<h1 class="planningstitel">Planning</h1>
<br>
<p class="errortext">De vakken met * zijn verplicht</p>
<form method="POST" action="planning.php">
<div class="form-group1">
Keuze spel:
<select name="Gamename" value="<?php $Gamename?>">
<option value="">Maak uw keuze</option>
<?php
foreach ($result as $row) {
?>
<option name="Gamename" value="<?php $Gamename?>"><?php echo $row["name"]?></option>
<?php
}
?>
</select>
<span class="error">* <?php echo $gamenameErr;?></span>
</div>
<div class="form-group2">
Starttijd:
<input type="time" class="form-control" name="Begintime" value="<?php $Begintime ?>">
<span class="error">* <?php echo $StarttimeErr;?></span>
</div>
<div class="form-group3">
Uitlegpersoon:
<input type="text" class="form-control" name="Instructor" value="<?php $Instructor ?>">
<span class="error">* <?php echo $InstructorErr;?></span>
</div>
<div class="form-group4">
Spelers:<br>
<input type="text" class="form-control-speler" name="Players" value="<?php $Players ?>">
<input type="text" class="form-control-speler"
<p>Niet alle textboxen bij Spelers hoeven ingevuld te worden</p>
</div>
<input type="submit" name="Submit">
<input type="reset">
</form>
</div>
</body>
</html>