I can't seem to get my Database to insert a customer...
It's in danish (the tags) but i think you can understand what happens anyways. We do connect to the database on the website, but it saids query failed...
Here's my contact form code:
<form action="elev.php" method="post">
<fieldset>
<label for="navn" style="float:left;">Navn:</label>
<input type="text" id="navn" name="navn" placeholder="Andreas Andreasen" />
<label for="email">Email:</label>
<input type="text" id="email" name="email" placeholder="Andreasandreasen@hotmail.com" />
<label for="telefonnummer">Telefon:</label>
<input type="number" id="telefonnummer" name="telefonnummer" placeholder="12345678" />
<label for="postnummer">Postnr:</label>
<input type="text" id="postnummer" name="postnummer" placeholder="8000" />
<input style="float:right;" type="submit" value="Opret" name="submit" />
</fieldset>
</form>
<form action="index.php">
<input style="float:left; margin-top:-51px;" type="submit" value="Startsiden">
</form>
<?php
$mysqli=mysqli_connect("localhost", "f413f_gr6", "xxxxxx", "f413f_gr6");
if (mysqli_connect_errno()) {
echo "Failed to connect: " . mysqli_connect_errno(); }
else {
echo "Connect success!<br>"; }
function performQuery($sql) {
global $mysqli;
if (mysqli_query($mysqli, $sql)) {
echo "Query Success!"; }
else {
echo "Query Failed!"; }
}
if (isset($_POST['submit'])) {
$navn = $_POST['navn'];
$email = $_POST['email'];
$telefonnummer = $_POST['telefonnummer'];
$postnummer = $_POST['postnummer'];
performQuery("INSERT INTO kunder(navn, email, telefonnummer, postnummer) VALUES ('$navn', '$email', $telefonnummer, '$postnummer')");
}
else {
echo "Tryk på submit";
}
?>
I think issues in your query with postnummer
is int data type as you shared database image so please replace your query with below query i will helps you.
performQuery("INSERT INTO kunder(navn, email, telefonnummer, postnummer) VALUES ('$navn', '$email', $telefonnummer, $postnummer)");
Replace your query with above i hope your issues will solve.your are trying to insert as string for postnummer may the reason you are getting error actually in your database datatype is int.