gpt4 book ai didi

php - 页面在本地主机上运行良好但无法在托管服务器上运行

转载 作者:搜寻专家 更新时间:2023-10-30 20:04:23 24 4
gpt4 key购买 nike

我创建了一个 PHP 网站,它在我的本地主机上运行良好,但是当我在服务器上上传相同的代码时,它在服务器上显示空白页面。

我怀疑的问题是我在代码中使用数据库连接 (dbc.php) 的任何地方我的页面都变得空白。当我删除该数据库连接代码时一切正常。

我正在输入登录代码和 dbc.php。

我的 login.php 代码

<?php


include('dbc.php');


// get form data, making sure it is valid
$phone = mysql_real_escape_string(htmlspecialchars($_POST['id']));
$pass = mysql_real_escape_string(htmlspecialchars($_POST['password']));

// check to make sure both fields are entered
if ($phone == '' || $pass == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';

// if either field is blank, display the form again
header("Location: " .$_SERVER['HTTP_REFERER']);
}
else
{
// save the data to the database

$login_sql=mysql_query("select * from member where email='$phone' and password='$pass'")
or die(mysql_error());
$num=mysql_num_rows($login_sql);

if($num>0)
{
session_start();
$admin_data=mysql_fetch_array($login_sql);
$_SESSION['usermatri_id']=$admin_data['mid'];


if($admin_data['mid']>0)
{
header("Location: dashboard.php");

}
else
{
header("location:".$_SERVER["HTTP_REFERER"]);
}

exit;
}
else{

header("location:".$_SERVER["HTTP_REFERER"]);
}
}



// if the form hasn't been submitted, display the form


?>

我的 dbc.php 代码

<?php
//connection to the database
mysql_connect("localhost","root","")or die(mysql_error('cannot connect'));
mysql_select_db("matrimony");
?>

1) 我尝试了这些问题,但没有运行

PHP is not working on server

PHP redirect not working on server

2) 我也尝试添加错误检查,网页上没有显示任何内容,甚至尝试查看 cPanel 错误日志。

ini_set('display_errors',1); 
error_reporting(E_ALL);

最佳答案

首先

下面的代码是非常非常错误的...

 if ($phone == '' || $pass == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';

// if either field is blank, display the form again
header("Location: " .$_SERVER['HTTP_REFERER']);
} else{
//the juice...
}

上面的意思是如果:

$_POST['id'] = 123456;
$_POST['password'] = 123456;

我还能喝“果汁


第二:

a) 确保 MySql 服务器已启动并正在运行。
b) 确保您尝试访问的数据库和表已正确导入。
c) 还要确保您有权访问该特定数据库。


第三:

从小做起

只需将以下内容添加到您的脚本中:

ini_set('display_errors',1); 
error_reporting(E_ALL);

mysql_connect("localhost","root","")or die(mysql_error('cannot connect'));
mysql_select_db("matrimony");

有什么错误吗?不,很好,继续添加小块代码,直到您找到造成您生命中浪费的 3 天的罪魁祸首。

在尝试了上面的方法之后,我要重复一遍,在尝试上面的方法之后如果你还有问题,请在我的答案下方评论,我会尽力帮助你。

关于php - 页面在本地主机上运行良好但无法在托管服务器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29753955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com