I'm trying to update an SQL database from GUI. If I fill out all the fields in the form it works, but if any of the fields is NULL or empty nothing will update. No error is thrown, but database won't update in phpmyadmin. I want to be able to accept NULL and empty fields, including be able to erase content in a field.
I'm not a programmer so I'd appreciate explanations on how to deal with these empty fields.
<?php
include ("connection.php");
include ("foundation.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP UPDATE DATA USING PDO</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form name="frmUser" method="post" action="">
<input type="text" name="id" required placeholder="id"><br><br>
<input type="text" name="person" required placeholder="person"><br><br>
<input type="text" name="dob" required placeholder="dob"><br><br>
<input type="text" name="dod" required placeholder="dod"><br><br>
<input type="submit" name="update" required placeholder="Update Data">
</form>
</body>
</html>
<?php
if(isset($_POST['update']))
{
// get values from input text and number
$id = $_POST['id'];
$person = $_POST['person'];
$dob = $_POST['dob'];
$dod = $_POST['dod'];
// mysql query to Update data
$pdoquery = "UPDATE people SET id=:id, person=:person,dob=:dob,dod=:dod WHERE id='" . $_GET['id'] . "'";
$pdoQuery_run = $pdocbcon->prepare($pdoquery);
$pdoQuery_exec = $pdoQuery_run->execute(array(":person"=>$person,":dob"=>$dob,":dod"=>$dod,":id"=>$id));
if($pdoQuery_exec)
{
echo 'Uppdaterat';
}
else
{
echo 'FEL';
}
}
?>