未知专栏'电子邮件'在where子句中

时间:2014-04-25 07:57:05

标签: php sql

我的代码有问题。它为我提供了“未知专栏”电子邮件'在where子句中。 我几乎尝试了一切,但我不知道问题是什么。我是初学者,所以请保持温柔:)

任何想法如何解决?

非常感谢

    session_start();
    include('connect.php');
    if(isset($_POST['submit']))
    //when isn't username in form
    if($_POST['firstname'] == '')
    {
        $_SESSION['error']['firstname'] = 'First name is required';
    }
    if($_POST['surname'] == '')
    {
        $_SESSION['error']['surname'] = 'Surname is required';
    }
    //when email isn't in form
    if($_POST['email'] == '')
    {
        $_SESSION['error']['email'] = 'Email is required';
    }
    //check if is email in correct format
    if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email']))
    {
        //email is in correct format and exist?
        $email = $_POST['email'];
        $sql1 = "SELECT * FROM users WHERE email = '$email'";
        $result1 = mysqli_query($connect, $sql1) or  die(mysqli_error($connect));
        if(mysqli_num_rows($result1) > 0)
        {
            $_SESSION['error']['email'] = 'Email is already used';
        }
    }
    else
    //error for wrong format of email
    {
        $_SESSION['error']['email'] = 'Your email is in wrong format';
    }
    //when isn't password in form
if($_POST['password'] == '')
{
    $_SESSION['error']['password'] = 'Password is required';
}
//when is error -> registration form
/*if(isset($_SESSION['error']))
{
    header("Location: index.php");
    exit();
}
else
*/
{
    $firstname = mysqli_real_escape_string($connect,$_POST['firstname']);
    $surname = mysqli_real_escape_string($connect,$_POST['surname']);
    $email = $_POST['email'];
    $password =  mysqli_real_escape_string($connect,$_POST['password']);
    $phone_number = mysqli_real_escape_string($connect,$_POST['phone_number']);
    $note = mysqli_real_escape_string($connect,$_POST['note']);

    $sql2 = "INSERT INTO users (firstname, surname, email, phone_number, note, password) VALUES ('$firstname', '$surname',
    '$email', '$phone_number', '$note','$password')";
    $result2 = mysqli_query($connect, $sql2) or die('Error: ' .mysqli_error($connect));

1 个答案:

答案 0 :(得分:0)

列名电子邮件可能错误或在数据库中不存在使用与数据库中定义的相同的列名