'where子句'查询中的未知列'email'

时间:2016-06-05 22:06:16

标签: php mysql sql email

database我无法正常运行注册码。我一直收到错误:

  

'where子句'中的未知列'email'

我做错了什么?我试过了:

$query = "SELECT * FROM register_login WHERE 'email' = '$email'";

它似乎工作但没有任何内容上传到我的数据库。早在2014年,这段代码工作得很好,但后来我弯腰使用了2年,现在它还没有工作

这是服务器代码:

       <?php


            if(isset($_POST['submit'])) {

        // Required field names
        $required = array('email');

        // Loop over field names, make sure each one exists and is not empty
        $error = false;
        foreach($required as $field) {
            if (empty($_POST[$field])) {
            $error = true;
            }
        }

            if ($error) {
                echo 'You forgot to fill in your email';
            } else {
                include("configur.php");
                $email = mysqli_real_escape_string($link, $_POST['email']);

          $query = "SELECT * FROM register_login WHERE email = '$email'";
                $result = mysqli_query($link, $query) or die(mysqli_error($link));

                if (mysqli_num_rows($result) ) {
                    print 'E-mail already exists. Please use a different email';
                }
                else {

          include('config.php');



      // table name 
     $tbl_name="pre_register";

      // Random confirmation code 
       $confirm_code=md5(uniqid(rand())); 




    $fname=$_POST['fname'];
     $lname=$_POST['lname'];

     $fdrink=$_POST['fdrink'];
      $fdrink1= hash("sha512", $fdrink);



       $email=$_POST['email']; 


      $password=$_POST['password']; 
      $encrypt_password= hash("sha512", $password);

     $confirmpassword=$_POST['confirmpassword']; 
     $encrypt_password1=hash("sha512", $confirmpassword);



     // Insert data into database 
     $sql="INSERT INTO $tbl_name(confirm_code, fname, lname, fdrink1, email, encrypt_password, encrypt_password1 )VALUES('$confirm_code', '$fname', '$lname', '$fdrink1',  '$email', '$encrypt_password', '$encrypt_password1')";
      $result=mysql_query($sql);

    // if suceesfully inserted data into database, send confirmation link to email 
     if($result){

    // ---------------- SEND MAIL FORM ----------------


   // send e-mail to ...
   $to=$email;

1 个答案:

答案 0 :(得分:0)

删除电子邮件周围的引号:

$query = "SELECT * FROM register_login WHERE email = '$email'";

其余的:此代码不安全。查看PHP-PDO如何编写安全代码。