PHP不会写入mysql

时间:2017-06-22 20:59:27

标签: php mysql

我的问题似乎是我的信息不会被保存到mysql数据库中,不仅如此,但我的Echos似乎也没有在我的IF语句中启动我确信这是一个简单的解决方法就在我面前但是我看不出我做错了什么,请帮忙吗?

<?php

    $firstname = "";
    $lastname = "";
    $email = "";
    $password_1 = "";
    $password_2 = "";
    $errors = array();

    $con = mysqli_connect('127.0.0.1','root','','registration');

    if(mysqli_connect_errno())
    {
        echo "Error Occured while connnecting with the Database ".mysqli_connect_errno();
    }

    if(isset($_POST['register']))
    {
        $firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
        $lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
        $email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
        $password_1 = filter_var($_POST['password_1'], FILTER_SANITIZE_STRING);
        $password_2 = filter_var($_POST['password_2'], FILTER_SANITIZE_STRING);

        if(empty($firstname))
        {
            array_push($errors,"First Name is required");
            echo "wtf";
        }
        if(empty($lastname))
        {
            array_push($errors,"Last Name is required");
            echo "wtf2";
        }
        if(empty($email))
        {
            array_push($errors,"Email is required");
            echo "wtf3";
        }
        if(empty($password_1))
        {
            array_push($errors,"Password is required");
            echo "wtf4";
        }
        if($password_1 != $password_2)
        {
            array_push($errors,"Password does not match");
            echo "wtf5";
        }

        if(count($errors) == 0)
        {
            $password_1 = md5($password_1);
            $sql = "INSERT INTO users('firstname','lastname','email','password') VALUES ('".$firstname."', '".$lastname."', '".$email."', '".$password_1."')";
            mysqli_query($con, $sql);
        }
    }
?>

0 个答案:

没有答案