I'm busy with an assignment of a course and I can't find out what the problem is. The only thing I know is that it's in the insert part. The connection is correct. As I'll show the variables, you can see the words which where put in the input fields. But they are still not in the database.
I used this code before and it worked but I don't see why it doesn't work at this moment. Can anyone please help me? Here below is the code I have.
Thank you for trying to help me!!
<?php
// Open connectie naar de database
$link = mysql_connect('localhost', 'root', 'root'); // maakt de connectie met de databases (mamp/wamp)
if (!$link) {
die('Geen connectie ' . mysql_error()); // verbreekt de verbinding en laat de error zien
}
$db_selected = mysql_select_db('voorbeeld', $link); // maakt connectie het database "voorbeeld"
if (!$db_selected) {
die ('Kan database niet selecteren : ' . mysql_error());// verbreekt de verbinding en laat de error zien
}
if ($_POST['submit'] == 'Verzenden') {
$naam = $_POST['naam'];
$boodschap = $_POST['boodschap'];
$datum = date("y-m-d");
// Bericht opslaan
$query2 = "INSERT INTO gastenboek (ID, naam, boodschap, datum)
VALUES(NULL, '$naam', '$boodschap', '$datum')";
$result = mysql_query($query2);
if (mysql_affected_rows() == 1) {
$success_msg = '<P>Uw bericht is geplaatst.</P>';
} else {
error_log(mysql_error());
$success_msg = '<P>Helaas, er ging iets mis.</P>';
}
}
$thispage = $_SERVER['PHP_SELF'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$form_page = <<< EOFORMPAGE
</head>
<body>
<H1>Uw bericht</H1>
$datum
$boodschap
$success_msg
<form method="POST" action="$thispage">
Uw naam:<br/>
<input type="text" SIZE="40" name="naam" value="$naam"><br/><br/>
Uw bericht:<br/>
<textarea name="boodschap" rows=10 cols=50>$boodschap</textarea><br/><br/>
<input type="submit" name="submit" value="Verzenden">
</form>
<a href="gastenboek.php"><input type="button" name="gastenboek" value="Gastenboek"></a>
</body>
</html>
EOFORMPAGE;
echo $form_page;
?>