I’ve set up this simple form that allows you to enter your personal details and have them stored in a DB, but it does not work.
Form HTML:
<html>
<body>
<form name="test" action="store.php" method="post">
Voornaam: <input type="text" name="first_name"> <br>
Achternaam: <input type="text" name="last_name"> <br>
E-Mail: <input type="text" name="e-mail"> <br>
Telefoon: <input type="text" name="phone"> <br>
Adres: <input type="text" name="address"> <br>
Postcode: <input type="text" name="postal_code"> <br>
Stad: <input type="text" name="city"> <br>
Provincie: <input type="text" name="province"> <br>
Land: <input type="text" name="country"> <br>
<input type="submit" value="Verzenden">
</form>
<body>
</html>
And the PHP:
<?php
/*Database test.
© 2013 Sydcul. All rights reserved.*/
//Please change the following settings:
/*Your database host*/ $host = "localhost";
/*Your database user*/ $user = "root";
/*Your database password*/ $password = "";
//Please don't change the following:
$connection = mysql_connect($host, $user, $password);
mysql_select_db("contact", $connection);
$debug = "INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country)
VALUES ('" . $_POST["first_name"] . "', '" . $_POST["last_name"] . "', '" . $_POST["e-mail"] . "', '" . $_POST["phone"] . "', '" . $_POST["address"] . "', '" . $_POST["postal_code"] . "', '" . $_POST["city"] . "', '" . $_POST["province"] . "', '" . $_POST["country"] . "')";
mysql_query("INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country)
VALUES ('" . $_POST["first_name"] . "', '" . $_POST["last_name"] . "', '" . $_POST["e-mail"] . "', '" . $_POST["phone"] . "', '" . $_POST["address"] . "', '" . $_POST["postal_code"] . "', '" . $_POST["city"] . "', '" . $_POST["province"] . "', '" . $_POST["country"] . "')");
echo $debug;
mysql_close($connection);
?>
I believe I got it to work once, but that was with only the first name.
I think it is something really obvious I don’t see, so please take some time to look at it and help me.
I put the debug stuff in for debugging, it shows me this:
INSERT INTO data (first_name, last_name, e-mail, phone, address, postal_code, city, province, country) VALUES ('John', 'Johnson', 'john@johnson.com', '1234567890', 'Street 1', '1234 AB', 'City', 'Province', 'Country')
Your email field
e-mailhas to be surrounded by the backtick character (`) such that your final query should be