+ 1

How to avoid big query in sql

$sql = "INSERT INTO `student_admission` (`adm_date`, `class`, `section`, `monthly_fee`, `monthly_fee_discount`, `name`, `date_of_birth`, `place_of_birth`, `identification_mark`, `cast`, `religion`, `mother_tongue`, `address`, `father_name`, `father_nic_no`, `father_qualification`, `occupation`, `mobile1`, `mobile2`, `whatsapp_no`, `email`, `picture`) VALUES ('{$_POST['adm_date']}', '{$_POST['adm_class']}', '{$_POST['adm_section']}', '{$_POST['adm_monthly_fee']}', '{$_POST['adm_monthly_fee_discount']}', '{$_POST['adm_name']}', '{$_POST['adm_dateofbirth']}', '{$_POST['adm_placeofbirth']}', '{$_POST['adm_identificationmark']}', '{$_POST['adm_cast']}', '{$_POST['adm_religion']}', '{$_POST['adm_mothertongue']}', '{$_POST['adm_address']}', '{$_POST['adm_fathername']}', '{$_POST['adm_fathernicno']}', '{$_POST['adm_fatherqualification']}', '{$_POST['adm_occupation']}', '{$_POST['adm_mobile1']}', '{$_POST['adm_mobile2']}', '{$_POST['adm_whatsappno']}', '{$_POST['adm_email']}', '$img_new_name')"; how i can short it

2nd Jul 2021, 9:05 AM
Syed Ahmed Raza Shah
Syed Ahmed Raza Shah - avatar
4 ответов
+ 3
Syed Ahmed Raza Shah Make dependent table means seperate table for different functionality like table for personal details, table for educational details, table for fee details. We have foreign key and primary key in database so we can link table with these keys. If you want to insert data at same time in different tables then use stored procedure.
2nd Jul 2021, 10:07 AM
A͢J
A͢J - avatar
+ 3
Your <$sql> variable is problematic cause you use single quotes to build the string and refer to array keys by string also enclosed in single quotes, leading to error for improperly quoted string. Also IIRC, single quoted string does not expand variable placeholders, so you might reconsider how you build that query. And I'm not sure why you wrap field values in curly brackets like so {$POST['adm_date']}
2nd Jul 2021, 2:09 PM
Ipang
+ 2
Also you need to add default value (e.g: "not mentioned") in case user didn't type in some fields. Use different tables in the same db connected to each other with foreign key.
2nd Jul 2021, 1:54 PM
Shadoff
Shadoff - avatar
+ 1
You need to add a primary key to the table called studentId of type integer.
4th Jul 2021, 12:36 AM
l4t3nc1
l4t3nc1 - avatar