-1
I am trying to record information from a form on a basis, but when I Gero the following code below is presented an error in the file saying that:
Notice: Undefined index: txtFirstName in C:\xampp\htdocs\begin\service.php on line 64
Notice: Undefined index: txtLastName in C:\xampp\htdocs\begin\service.php on line 65
Notice: Undefined index: ddlGender in C:\xampp\htdocs\begin\service.php on line 66
Notice: Undefined index: txtMinutes in C:\xampp\htdocs\begin\service.php on line 67
Notice: Undefined index: txtSeconds in C:\xampp\htdocs\begin\service.php on line 68
Notice: Undefined variable: mysqli_query in C:\xampp\htdocs\begin\service.php on line 74
Fatal error: Uncaught Error: Function name must be a string in C:\xampp\htdocs\begin\service.php:74 Stack trace: #0 {main} thrown in C:\xampp\htdocs\begin\service.php on line 74
The code I am using to define the variables is this, which is corresponding to the above error lines.
I am not a PHP Expert and I didn’t find any answers to my respective problem in the PHP doc. Could someone please help me. I’m using the PHP7
$fname = htmlspecialchars($_POST['txtFirstName']);
$lname = htmlspecialchars($_POST['txtLastName']);
$gender = htmlspecialchars($_POST['ddlGender']);
$minutes = htmlspecialchars($_POST['txtMinutes']);
$seconds = htmlspecialchars($_POST['txtSeconds']);
$time = $minutes . ':' . $seconds;
My Internet is like this:
$mysqli_query($conect, 'INSERT INTO runners(first_name, last_name, gender, finish_time) values("$fname", "$lname", "$gender", "$time")');
undefined index
means that the array$_POST
does not contain the indexes you are looking for. You need to check if there is anything in this array. You can useisset
or the operator null coalesces (??
)– fernandosavio