Undefined array key warning

I have a form to upload to database. if i select panelyes on the form and submit it inserts correctly but sends me a warning about panelno because it was not selected?

Warning : Undefined array key “panelno” in /blah blah blah.php on line 10


$con = mysqli_connect('localhost', 'mydb', 'mypassword','mydb');

// get the post records
$date = $_POST['date'];
$panelyes = $_POST['panelyes'];
$panelno = $_POST['panelno'];

// database insert SQL code
$sql = "INSERT INTO firesystem (date, panelyes,panelno) VALUES ('$date', '$panelyes', '$panelno')";

// insert in database 
$rs = mysqli_query($con, $sql);

	echo "Contact Records Inserted";


If an input is optional, and may not exist, you need to either use isset() or the null coalescing operator ?? to test if it does or does not exist, and setup a default value to use if it doesn’t exist.

Sponsor our Newsletter | Privacy Policy | Terms of Service