Hi,
Thank you in advance for anyone who can help with this, anyways. This is a school project and I am trying to insert some information from a form into the mysql database I’ve made. I already know that the connection to the database has been successful, and also that I am able to retrieve information from the form. The problem occurs when I run the site and it gives me the message saying that this ($conn->query($query)) requirement has not been fulfilled, which indicates there is something wrong with the INSERT query.
Here is how my form and php looks like:
<form action="nyttmedlem.php" method="post">
Fornavn
<input type="hidden" name="dykkerID" value="NULL"/>
<input type="text" name="fnavn" required>
Etternavn
<input type="text" name="enavn" required>
<input type="submit" name="sendinn" value="Send Inn">
</form>
<?php
// Create connection
$servername="localhost";
$username="root";
$password="";
$db="dykking";
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
echo "Connected successfully";
$date="date('Y-m-d')";
$fnavn=$_POST['fornavn'];
$enavn=$_POST['etternavn'];
echo "<br>Du heter $fnavn $enavn";
$query="INSERT INTO dykking.dykker (`dykkerID`, `fornavn`, `etternavn`, `medlemsiden`) VALUES (NULL,'$fnavn','$enavn','$date')";
If ($conn->query($query)){
echo "Ønskene er registrert<br>";
}
else {
echo "<br>Something went wrong";
}
}
?>
I suspect the problem might be in the NULL value or $dato value in which the NULL value is in mysql an auto increment that should be filled in automatically when added to the db.
Thank you for any help, appreciate it!