Level 102
Can you show the form? Seems you don't have an input named "gender"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
errors
: Undefined array key "gender" in
C:\laragon\www\php phonebook project\crud\School Management System\forms\student\create.php
on line
17
Deprecated
: mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated in
C:\laragon\www\php phonebook project\crud\School Management System\forms\student\create.php
on line
my code
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$firstName = mysqli_real_escape_string($conn, $_POST['first_name']);
$lastName = mysqli_real_escape_string($conn, $_POST['last_name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$dob = mysqli_real_escape_string($conn, $_POST['dob']);
$fatherName = mysqli_real_escape_string($conn, $_POST['father_name']);
$mobile_no = mysqli_real_escape_string($conn, $_POST['mobile_no']);
$city = mysqli_real_escape_string($conn, $_POST['city']);
$district = mysqli_real_escape_string($conn, $_POST['district']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$state = mysqli_real_escape_string($conn, $_POST['state']);
$nationality = mysqli_real_escape_string($conn, $_POST['nationality']);
$image = __FILE__['image']['name'];
// $imageType = __FILE__['image']['type'];
// $imageSize = __FILE__['image']['size'];
// $imageTemp = __FILE__['image']['temp_name'];
$errors = [];
if(strlen($_POST['first_name']) == 0){
$errors['first_name'] = "First name is required.";
}
else if(strlen($_POST['first_name']) <= 3){
$errors['first_name'] = "First name cann't be less than 3 characters.";
}
// //image Validation
// if($imageType != 'image/jpg' || 'image/jpg')
// {
// $errors['image'] = "Please use image type of jpg/png.";
// } else if($imageSize > 2000) {
// $errors['image'] = "Image should not be more than 2MB.";
// } else {
// move_uploaded_file($imageTemp, __DIR__ . '/../../images/students');
// }
if(empty($errors))
{
$sql = "INSERT into `students`
(first_name, last_name, email, dob, father_name, mobile_no, city, district, gender, state, nationality, image)
values('$firstName', '$lastName', '$email', '$dob', '$fatherName', '$mobile_no', '$city',
'$district', '$gender','$state', '$nationality', '$image'
)";
$query = mysqli_query($conn, $sql);
$_SESSION['msg'] = "Stored Successfully!";
// header("location:/");
}
}
Please or to participate in this conversation.