# Undefined array key warning

**URL:** <https://www.phphelp.com/t/undefined-array-key-warning/35444>\
**Category:** General PHP Help\
**Created:** [May 13, 2023, 11:01pm UTC](https://www.phphelp.com/t/undefined-array-key-warning/35444 "2023-05-13T23:01:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![webchambers](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@webchambers](https://www.phphelp.com/u/webchambers)\
**Post date:** [May 13, 2023, 11:01pm UTC](https://www.phphelp.com/t/undefined-array-key-warning/35444/1 "2023-05-13T23:01:10Z")

</div>

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**

```auto
<?php

$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);

if($rs)
{
	echo "Contact Records Inserted";
}

?>

```

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [May 14, 2023, 1:00pm UTC](https://www.phphelp.com/t/undefined-array-key-warning/35444/2 "2023-05-14T13:00:22Z")

</div>

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.
