我创建了一个在localhost中工作的网站但是当我将这些页面上传到服务器时,只有php页面显示为空白,html页面工作正常 . This is my php code in my page :-
<?php
session_start();
include_once 'dbconnect.php';
if(isset($_SESSION['user'])!="")
{
header("Location: home.php");
}
if(isset($_POST['btn-login']))
{
$email = mysql_real_escape_string($_POST['email']);
$upass = mysql_real_escape_string($_POST['pass']);
$res=mysql_query("SELECT * FROM users WHERE email='$email'");
$row=mysql_fetch_array($res);
if($row['password']==md5($upass))
{
$_SESSION['user'] = $row['user_id'];
header("Location: home.php");
}
else
{
?>
<script>alert('wrong details');</script>
<?php
}
and code for dbconnect.php
<?php
if(!mysql_connect("localhost","root",""))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("member"))
{
die('oops database selection problem ! --> '.mysql_error());
}
?>
2 回答
2需要改进:
1.将所有
mysql_*
函数更改为mysqli_*
2.将
if(!mysql_select_db("member"))
更改为if(!mysql_select_db($con , "member"))
,因为此函数接收2参数1是$con
变量,其中您必须存储数据库的连接,即$con = mysqli_connect("localhost","root","");
希望这会对你有所帮助
这可能是弃用的错误,如果它只是连接,你将在页面上得到至少你的错误输出 .
所以尝试迁移到
mysqli
(不推荐使用mysql,所以如果你的服务器在PHP7上运行,它就不再可访问了) .并改变:
至 :
确保输入正确的数据库信息 .
并用
mysqli
等效替换每个mysql
方法,你必须使用那个$db
变量 .