PHP empty field validation

前端 未结 4 1067
感情败类
感情败类 2021-01-14 05:48

I have a enrollment form where users have to input there address. I am using PHP for validation and currently I check to make sure the field is not empty. Here is my code:

4条回答
  •  太阳男子
    2021-01-14 06:21

    You already use trim() on the insert, why not call it once in the beginning, and test that value?

    $user_address = trim($_POST['address']);
    
    if (empty($user_address)) {
        $msg = 'You must enter an address' ;
    } else {
        $address = mysqli_real_escape_string($dbc, strip_tags($user_address)) ;
    }
    

提交回复
热议问题