'How to test a php login connected to a mysql db through xampp?

hello this is my first post on stackoverflow i am at beginner level at php, mysql and work on a php log in page connected to a mysql database which i did try to test through xampp and getting the following error message

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

I was able to successfully connect to the mysql database through dreamwavercs6 on win7 64bit and created a user for the db as also i created a administrator with full privileges in the created admin table. With a successful log in it should direct you to a follow up page called index.php which is a second index page only for admins to choose tasks, located in a subfolder in the same directory. The home page index.php is located here C:\xampp\htdocs\myonlinestore\index.php\

the file with the script called admin_login.php is shown under here

<?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();
}
}
?>

the script connect_to_mysql.php under here

 <?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");             
?>

the script index.php which is the landing page where on successful login from admin_login should redirect you to, under here

<?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();
}
?>

the problem is that i can not log in through my firefox browser and getting the error as mentioned at the top. All addons,extensions in my firefox browser are on disable and accepting cookies is selected, can anyone help to fix this problem?

Many thanks in advance



Solution 1:[1]

Here in your script you are not being able to include your connect_to_mysql.php file.

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

You are trying to provide relative path. Make sure you are properly able to access that file from relative path you are including. i.e. your admin_login.php file.

You can try passing absolute path in your include:

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

please check path in your file manager if it is correct absolute path.

Solution 2:[2]

Remove one of the dots from the include("../if the scripts are in

C:\xampp\htdocs\myonlinestore\storescript.

From

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

"../" will take you to htdocs, so you need "./" to get to htdocs\myonlinestore

Solution 3:[3]

may be it will help you.

<?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";
}
?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 davejal
Solution 3 User558