0

您好,这是我在 stackoverflow 上的第一篇文章,我是 php、mysql 的初学者,并且在连接到 mysql 数据库的 php 登录页面上工作,我确实尝试通过 xampp 进行测试并收到以下错误消息

Warning: include(../storescripts/connect_to_mysql.php): failed to open stream: No such
file or directory in C:\xampp\htdocs\myonlinestore\storeadmin\admin_login.php 
on line 15

Warning: include(): Failed opening '../storescripts/connect_to_mysql.php' for
inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\myonlinestore
\storeadmin\admin_login.php on line 15

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in 
C:\xampp\htdocs\myonlinestore\storeadmin\admin_login.php on line 18
That information is incorrect, try again Click Here

我能够在win7 64位上通过dreamwavercs6成功连接到mysql数据库,并为数据库创建了一个用户,我还在创建的管理表中创建了一个具有完全权限的管理员。成功登录后,它应该会引导您进入一个名为的后续页面index.php,该页面是第二个索引页面,仅供管理员选择任务,位于同一目录的子文件夹中。主页index.php位于此处C:\xampp\htdocs\myonlinestore\index.php\

带有调用脚本的文件admin_login.php显示在此处

<?php
session_start();
if (isset($_SESSION["manager"])){
header("location: index.php");
exit();
}
?>
<?php
if (isset($_POST["username"]) && isset($_POST["password"])){

$manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
$password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);

include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND
password='$password' LIMIT 1");
$existCount = mysql_num_rows($sql);
if ($existCount == 1){
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $manager;
$_SESSION["password"] = $password;
header("location: index.php");
exit();
} else {
echo 'That information is incorrect, try again <ahref="index.php">Click Here</a>';
exit();
}
}
?>

connect_to_mysql.php这里的脚本

 <?php 
$db_host = "localhost";
$db_username = "user"; 
$db_pass = "user"; 
$db_name = "myonlinestore_db";

mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to
mysql");
mysql_select_db("$db_name") or die ("no database");             
?>

作为登录页面的脚本index.php,成功登录后admin_login应将您重定向到此处

<?php
session_start();
if(!isset($_SESSION["manager"])){
header("location: admin_login.php");
exit();
}
$managerID = preg_replace('#[^0-9]#i', '',$_SESSION["id"]);
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]);
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]);

include"../storescripts/connect_to_mysql.php";
$sql=mysql_query("SELECT*FROM admin WHERE id='$managerID' AND username='$manager' AND
password='$password' LIMIT 1"); // query the person

$existCount=mysql_num_rows($sql); // count the nums
if ($existCount==0){//evaluate the count
echo "Your login session data is not on record in the database";
exit();
}
?>

问题是我无法通过我的 Firefox 浏览器登录并收到顶部提到的错误。我的firefox浏览器中的所有插件,扩展都处于禁用状态并选择接受cookie,有人可以帮助解决这个问题吗?

提前谢谢了

4

3 回答 3

0

在您的脚本中,您无法包含您的 connect_to_mysql.php 文件。

include "../storescripts/connect_to_mysql.php";

您正在尝试提供相对路径。确保您能够正确地从您包含的相对路径访问该文件。即您的 admin_login.php 文件。

您可以尝试在包含中传递绝对路径:

include "C:\xampp\htdocs\myonlinestore\storescripts\connect_to_mysql.php";

如果绝对路径正确,请检查文件管理器中的路径。

于 2013-08-29T18:46:46.277 回答
0

include("../如果脚本在其中,则删除其中一个点

C:\xampp\htdocs\myonlinestore\storescript。

C:\xampp\htdocs\myonlinestore\storeadmin\admin_login.php

"../" 将带你到 htdocs,所以你需要 "./" 才能到达htdocs\myonlinestore

于 2016-01-29T14:26:54.260 回答
0

也许它会帮助你。

<?php
   $server = "localhost";
   $connection = mysqli_connect ($server,"root","","your_database_name");
   if(!$connection){
    // if not connected it will gives the error here
    echo "server not found".mysql_error();
}   
else{
    echo "Connected";
}
?>
于 2017-03-06T05:15:57.750 回答