I just started with PHP and SQL and wanted to insert a submitted form into a mysql table. I got a lot of things from already answered questions here, but now encountered the problem that the data is not inserted into the table and I do not get any errormessage. Checking it with affected_rows results in -1 but I am unable to find my mistake.
The form
<form method="post" action="anmeld.php">
<table>
<tr>
<td>
Familie/Name:
</td><td>
<input type="text" name="name" required>
</td>
</tr>
<tr>
<td>
Wir kommen Ja <input type="radio" name="anwesend" value="ja" checked>
Nein <input type="radio" name="anwesend" value="nein">
</td>
</tr>
<tr>
<td>
Wir sind
</td>
<td><input type="number" name="adult"> Erwachsene.
</td>
</tr>
<tr>
<td><br> Unsere Kinder sind<br>
Kind <br>Kind<br>Kind<br>Kind
</td>
<td><br><br>
<input type="number" name="child1"> Jahre alt. <br><input type="number" name="child2"> Jahre alt. <br><input type="number" name="child3"> Jahre alt. <br><input type="number" name="child4"> Jahre alt.
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Abschicken">
</td>
</tr>
</table>
php insert
<?php
$mysqli = new mysqli("127.0.0.1", "user", "userpw", "dbname");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_err;
}
if (!empty($_POST["submit"])) {
$familie = $_POST["name"];
$anwesend = $_POST["anwesend"];
$adult = $_POST["adult"];
$child1 = $_POST["child1"];
$child2 = $_POST["child2"];
$child3 = $_POST["child3"];
$child4 = $_POST["child4"];
$sql = "INSERT INTO 'guests' ('id', 'familie', 'anwesend', 'adult', 'child1', 'child2', 'child3', 'child4')
VALUES ('', '$familie', '$anwesend', '$adult', '$child1', '$child2', '$child3', '$child4')";
$mysqli->query($sql);
printf("Affected rows (INSERT): %d\n", $mysqli->affected_rows);
}
?>
I think it's something really obvious, I simply overlook but I hope that you guys could help me.
EDIT: yeah it's been the ` and '. Now works fine. Thank you guys