I'm trying to create a user registration script for my website, and although my current code works, I'm wondering if the syntax is correct, and if there are modifications that I need to make to increase security and avoid mistakes.
My registration form has multiple fields, some of which cannot be null (ex. email and password), and some of which can be null (ex. birthdate). Each field has jquery / client-side validation, and the form cannot be submitted until the required fields are set. After checking if the registration form has been submitted, I'm saving up the information in different variables as follows:
$email=isset($_POST['email']) ? $database->escape($_POST['email']) : "";
$birthdate=isset($_POST['birthdate']) ? $database->escape($_POST['birthdate']) : "";
I know I need to escape the information before saving, which is what the escape function does in this case, but other than that, I'm wondering if my approach/logic is wrong?
Should I be checking both isset and empty for each field, or should I have a different approach for fields that can be null and those that can't?. Ex:
$email=isset($_POST['email'])&&!empty($_POST['email']) ? $database->escape($_POST['email']) : "";
Or is checking for !empty enough in such case?
$email=!empty($_POST['email']) ? $database->escape($_POST['email']) : "";
Before the sql insertion I'm checking if(empty($email)) in which case the registration doesn't go through, so I'm confused as to if I do need both the isset and empty checks when first retrieving the information and saving it to variables.
Thanks for any help/advice you can give me on this topic. I graduated 2 years ago and have mostly worked on frontend web design, I learned php and mysql in school during my last two years, but nowhere in my notes or practice files do I see a mention of isset to check if a value is received, they all save the post or get straight to the variable, and there was no mention of mysqli or pdo, just mysql which I know has been deprecated (and apparently there were warnings of this happening before they even thought me about it). Looks like my teachers were behind on this practices, I've learned so much about php and mysqli in the last few days only while working on this project, I'm still confused by a lot of things although I think I'm getting the hang of it.