我收到的错误是这样的:
SELECT * FROM tenants WHERE ic='123456789'
未选择数据库。
如果我已经选择了我的数据库,为什么它没有选择数据库。 这是我的PHP代码:
require "../config/database.php";
$error_text = "Oops! This is a registered identification number! Please check in the tenants list.";
// checking ic already exists
$sql="SELECT * FROM tenants WHERE ic='$ic' ";
$result=mysqli_query($conn,$sql);
if($error_mysql){
echo $error_mysql;
}
return ($result) ? $error_text : "valid";`
这是我的database.php代码:
/* Define your data to access MySQL database */
define("REG_USER", "root"); // your username
define("REG_SERVER", "localhost"); // your host
define("REG_PASSWORD", ""); // your password
define("REG_DATABASE", "rsystem"); // your database
/* Variables */
$error_exists = false;
$error_mysql = "";
/* Connection to DB */
/* Constants, that defined in action.php, are used */
$conn = mysqli_connect(REG_SERVER, REG_USER, REG_PASSWORD, REG_DATABASE);
if (mysqli_connect_error()) {
$error_mysql = ("Error connecting to database (" . mysqli_connect_errno() . ") ". mysqli_connect_error());
}
mysqli_set_charset($conn, 'utf8');
感谢。