我正在尝试做一个简单的连接mysql服务器。但是当我尝试输入数据或连接到数据库时,我收到了这个错误。
致命错误:未捕获错误:调用未定义函数mysql_select_db() 第99行的E:\ wamp64 \ www \ admin \ adminpanel \ login.php (!)错误:调用未定义的函数mysql_select_db() 第99行的E:\ wamp64 \ www \ admin \ adminpanel \ login.php
在我的PHP代码下面;
<?php require_once('connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Bu sitede giriş isteklerini doğrula.
if (!isset($_SESSIBuN)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['kullanici_adi'])) {
$loginUsername=$_POST['kullanici_adi'];
$password=$_POST['kullanici_sifre'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = false;
mysql_select_db('form_database', $conn);
$LoginRS__query=sprintf("SELECT kullanici_adi, kullanici_sifre FROM admin_yoneticiler WHERE kullanici_adi=%s AND kullanici_sifre=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $admin) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Form Kontrol Paneli Giriş</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<style type="text/css" media="screen">
.col-md-offset-36 {
margin-left: 36%;
}
.margin-top20 {
margin-top: 20px;
}
.margin-top100 {
margin-top: 100px !important;
}
.b-white {
background-color: #fff;
}
.content {
min-height: 540px;
}
.footer {
border-top: 1px solid #EDEDED;
}
.makeauthor {
float: right;
}
</style>
</style>
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<div class="container margin-top100">
<div class="row">
<div class="col-md-4 col-md-offset-36">
<a href="./index.php"><img src="img/your_logo.png" alt="Form Kontrol Paneli"></a>
</div>
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-body">
<h5 class="text-center">
Yönetici Girişi</h5>
<form class="form form-signup" role="form" name="login" method="POST" action="<?php echo $loginFormAction; ?>">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="kullanici_adi" class="form-control" placeholder="Yönetici Adınız" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="kullanici_sifre" class="form-control" placeholder="Yönetici Şifreniz" />
</div>
</div>
</div>
<button type="submit" name="giris" class="btn btn-sm btn-primary btn-block" role="button">Giriş Yap</button>
</form>
</div>
</div>
</div>
答案 0 :(得分:2)
你应该使用mysqli_connect而不是mysql_connect来获取最新的php版本
$link = mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db($link, $db_name)or die("cannot select DB");
或尝试pdo
<?php
$db=new PDO('mysql:host=localhost;dbname=$dbname;charset=utf8mb4', 'root', '') or die("Could connect to Database");
?>