您好,这是我在 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,有人可以帮助解决这个问题吗?
提前谢谢了