你好,这是我在stackoverflow上的第一篇文章,我在php、mysql方面处于初级水平,并在连接到mysql数据库的php登录页面上工作,我确实尝试通过examplep测试该数据库,并得到以下错误消息
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 64bit上的dreamwavercs6成功连接到mysql数据库,并为该数据库创建了一个用户,同时我还在创建的admin表中创建了一名具有完全权限的管理员。成功登录后,它会将您引导到名为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,有人能帮助解决这个问题吗?
提前感谢
在脚本中,您无法包含connect_to_mysql.php文件。
include "../storescripts/connect_to_mysql.php";
您正在尝试提供相对路径。确保您能够从包含的相对路径正确访问该文件。即admin_login.php文件。
你可以尝试在你的包中通过绝对路径:
include "C:'xampp'htdocs'myonlinestore'storescripts'connect_to_mysql.php";
请在文件管理器中检查路径是否为正确的绝对路径。
如果脚本在中,则从include("../
中删除其中一个点
C: ''examplep''htdocs''myonlinestore''storescript。
来自
C: ''examplep''htdocs''myonlinestore''storeadmin''admin_login.php
"../"将带您访问htdocs,因此您需要"./"才能访问htdocs'myonlinestore
可能会对您有所帮助。
<?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";
}
?>