我正在尝试使用php脚本连接到数据库,但它无法正常工作,但出现此错误:我尝试将mysql更改为mysqli,但我也无法正常工作
致命错误:未捕获错误:调用/storage/ssd3/564/6656564/public_html/login.php:8中的未定义函数mysql_connect()堆栈跟踪:#0 {main}抛出于/ storage / ssd3 / 564 /第6行的6656564 / public_html / login.php
这是我的php代码
<?php
// Database Things =========================================================
//These values can be found in the email.
$host = "localhost"; //<--put your host here
$user = "******"; //<-- put username here
$password = "R*****"; //<--put your password here
$dbname = "id6*****_users"; //<-- put your database name here
mysql_connect($host, $user, $password) or die("Cant connect into database");
mysql_select_db($dbname)or die("Cant connect into database");
// =============================================================================
$Act = $_GET["Act"];// what is action, Login or Register?
$nick = $_GET["User"];
$pass = $_GET["Pass"];
$Email = $_GET["Email"];
if($Act == "Login"){
if(!$nick || !$pass) {
echo "Login or password cant be empty.";
} else {
$SQL = "SELECT * FROM Users WHERE Username = '" . $nick . "'";
$result_id = @mysql_query($SQL) or die("DB ERROR");
$total = mysql_num_rows($result_id);
if($total) {
$datas = @mysql_fetch_array($result_id);
if(!strcmp($pass, $datas["Password"])) {
echo "Correct";
} else {
echo "Wrong";
}
} else {
echo "No User";
}
}
}
if($Act == "Register"){
$checkuser = mysql_query("SELECT Username FROM Users WHERE Username='$nick'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0)
{
echo "TAKEN";// Username is taken
unset($nick);
exit();
}else{
$query = "INSERT INTO Users (Username, Password,Email) VALUES('$nick', '$pass', '$Email')";
mysql_query($query) or die("ERROR");
mysql_close();
echo "Registered";
}
}
// Close mySQL Connection
mysql_close();
?>
如果有人可以帮助我,那将很棒
答案 0 :(得分:-1)
如果要连接到本地数据库,请使用此变量
$host = "localhost"; //<--put your host here
$user = ""; //<--put your db username here
$password = ""; //<--put your db password here
$dbname = put your database name here in string
mysql_connect($host, $user, $password) or die("Cant connect into database");
mysql_select_db($dbname)or die("Cant connect into database");
如果要使用服务器数据库连接到站点,请使用此
将用户连接到数据库(从下拉列表中选择)
$host = "localhost"; //<--put your host here
$user = $db_user;
$password = $db_password ;
$dbname = $databse_name;
mysql_connect($host, $user, $password) or die("Cant connect into database");
mysql_select_db($dbname)or die("Cant connect into database");