脚本没有连接

时间:2016-06-11 02:38:41

标签: javascript php jquery sql

我正在使用JS将用户注册到我的数据库。我的脚本的寄存器部分以前工作过。我用check扩展了我的脚本。如果用户输入的$ name正在使用,则脚本checks。如果正在使用,脚本需要显示echo "Name is in use";

当我运行此脚本时,我得到die('Error: ' . mysqli_error($con));

在我的浏览器中,我得到:Error:

我的剧本出了什么问题?

function register($name,$email,$password) {

 $errors      = array();
 $messages    = array();

 if( empty($name)=== true || empty($email)=== true || empty($password) === true  ) {
  die("One ore more fields are empty");   
 }
 else
 {    
  $query = mysqli_query($conn, "SELECT * FROM users WHERE name='".$name."'");
  if(mysqli_num_rows($query) > 0) {
   echo "Name is in use";
  }
  else
  {
   $name = trim($name);
   $email = trim($email);
   $password = trim($password);

   $sql = "INSERT INTO users (name, email, password) VALUES('$name','$email',md5('$password'))";
   $result=mysqli_query($sql);

   if($result) {
    echo "Success";
   }

   if (!mysqli_query($conn,$query))
   {
    die('Error: ' . mysqli_error($conn));
   }
  }
 }
}

$ conn在已包含的另一个脚本中定义:

<?php

define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DBNAME','db');

class Connection {

    private static $_instace;
    private $conn;

    private function __construct() {
        $this->conn = mysqli_connect(HOST, USER, PASS);
        mysqli_select_db(DBNAME);
    }

    public static function getconnect() {
        if (!self::$_instace) {
            self::$_instace = new Connection();
        }
        return self::$_instace;
    }

    public function mysqli_execute($sql) {
        $sql = ltrim($sql);
        $arr_get = array();
    }

    private function __close() {    
    }
}
?>

0 个答案:

没有答案