Insert formular problemer
Jeg har en insertformular, som jeg ikke kan få til at skrive i databasen.<html>
<head>
</head>
<body>
<form name="test" method="post">
<?php
$dbhost = 'localhost';
$dbname = 'userstest';
$dbuser = 'root';
$dbpass = '******';
$link = new mysqli($dbhost, $dbuser, $dbpass ,$dbname);
mysqli_set_charset($link,"utf8");
?>
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="phone">
<input type="submit" name="submit" value="Submit">
<?php
if (isset($_POST['submit'])) {
$nam = $_POST['name'];
$mail = $_POST['email'];
$tlf = $_POST['phone'];
$sql = mysqli_prepare($link,"INSERT INTO users (name, email, phone) VALUES (?,?,?)") or die(mysqli_error($link));
$sql->bind_param("ssi", $nam,$mail, $tlf);
$sql->execute();
$success_message= $sql->get_result();
echo $success_message;
if($sql->execute()) {
$success_message = "Added Successfully";
echo $success_message;
} else {
$error_message='';
echo("Error description: " . mysqli_error($link));
echo $error_message;
}
$sql->close();
}
?>
</form>
</body>
</html>
I databasen hedder det første felt 'id'. Der kommer en meddelelse:
"Error description: Field 'id' doesn't have a default value"
Hvis jeg sletter feltet i databasen kommer den blot med næste felt:
"Error description: Field 'name' doesn't have a default value"
Kan være opsætningen af databasen?. Jeg bruger Wamp 3.2.3 - Mysqli 5.7.31