1
I’m having trouble recording null value in foreign key. When I save to my phonebook with id_pessoa
blank, it records 0 and not null. How can I fix it?
This I my code and table :
person:
id_pessoa int(11) NOT NULL AUTO_INCREMENT,
ds_pessoa varchar(20) DEFAULT NULL,
agenda:
id_agenda int(11) NOT NULL AUTO_INCREMENT,
hr_agendamento time(11) DEFAULT NULL,
id_pessoa int(11) DEFAULT NULL,
Php code
<?php
$hr_agendamento = $_POST['hr_agendamento'];
$id_pessoa = $_POST['id_pessoa'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO agenda (hr_agendamento, id_pessoa)
VALUES ( $hr_agendamento, $id_pessoa)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
thanks friend worked perfectly..
– Sergio Silva