Jump to content

Database not connecting, on a car rental system.


psd99

Recommended Posts

Hello everyone,

 

I am currently building a carrental system using php, mysql and apache.

 

I have sucessfully installed XAMPP and created all my tables.

 

 

The following code is in my conff.php file (Config)

 

 

this should connect me to my database:

 

<?php

// Session Start

session_start();

// Connect to database carrentals

$connect=$_REQUEST["connect"];

$connect=mysql_connect('localhost','root','diamond');

// Database Selection

$database = "carrentals";

// Error message if connection to database fails

if (!$connect) die ("Error: Couldn't Connect to the database server. For more information and help, consult your IT support.");

// Error message if

mysql_select_db($database,$connect) or die ("Error: Unable to open database.");

// Username setting

$username=$_SESSION["valid_user"];

?>

 

 

On my main page I have to type in my  username and password.

 

I typed in root

and then diamond.

 

At first I was getting an error that was telling me something was wrong with my file called checklogin.php

I now get the error

 

 

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

 

If you think this is a server error, please contact the webmaster.

 

Error 404

 

on the page: http://localhost/login.php

 

 

the main index has this code on it:

 

</style>

</head>

<form name="login" method="post" action="checklogin.php">

<body>

<table width="1119" height="435" border="0" align="center">

 

and the php login file is this:

but its called checklogin.php

 

 

<?php

ob_start();

include("conn.php");

session_start();

if ($_SESSION['accesslevel'] == "Admin") { header("Location: adminhome.php"); exit; }

if ($_SESSION['accesslevel'] == "User") { header("Location: main.php"); exit; }

 

///$_SESSION['message'] ="";

$username=$_POST['username'];

$password=$_POST['password'];

 

$query = "SELECT * FROM staff WHERE staff_username='$username' and staff_password='$password' and staff_level= '0'";

$result= mysql_query($query);

$count= mysql_num_rows($result);

 

if($count==0){

 

$query2 = "SELECT * FROM staff WHERE staff_username='$username' and staff_password='$password' and staff_level= '1'";

$result2= mysql_query($query2);

  $count2= mysql_num_rows($result2);

if($count2==0){

header("location: login.php"); $_SESSION['message']="Wrong

Username/Password"; exit; };

};

 

if($count2==1){

$_SESSION['accesslevel'] = 'Admin';

while ($res2= mysql_fetch_array($result)){

$_SESSION['username'] = $res['staff_username'];

}

 

}

 

if($count==1){

$_SESSION['accesslevel'] = 'User';

while ($res2= mysql_fetch_array($result)){

$_SESSION['username'] = $res2['staff_username'];

$_SESSION['firstname'] = $res2['staff_fname'];

$_SESSION['lastname'] = $res2['staff_sname'];

}

}

 

if ($_SESSION['accesslevel'] == "Admin") { header("Location: adminhome.php");

exit; }

if ($_SESSION['accesslevel'] == "User") { header("Location: main.php");

exit; }

?>

 

 

 

I am killing myself here over this, I am adamant that I am making a silly error but not so sure what I am doing wrong.

 

Can you please suggest what I should do next, apart from hang myself!

 

Thanks

 

psd99

 

 

 

 

Link to comment
Share on other sites

Should included filename be "conn.php" or "conff.php"?

 

If the included file contains session_start() why call it again?

 

Put error checks after queries ... or die (mysql_error())

 

Use code tags when posting code

 

 

Thanks for replying.

 

Hi sorry my bad

 

the file is actually called config.php

 

also not so sure about how to tag my code on here, I will look into this.

 

the problem right now is that

when I type in my username and password it is done on a page called index.php

 

This page has a submit button that should check a file called checklogin.php

but instead it goes to login.php

and this does not exist, which causes an error. I have tried to change the name in the index.php file to login.php but then on the webbrowser it goes to checklogin.php

does that make sense?

 

 

It is very confusing I had my friend over just spent 4 hours trying to sort this out with no luck.

 

 

you mentioned that I should put error checks after queries is this purely for educational purposes?

 

 

thanks for your time

 

psd99

 

Link to comment
Share on other sites

if "login.php" does not exist, why do you have this

 

$query2 = "SELECT * FROM staff WHERE staff_username='$username' and staff_password='$password' and staff_level= '1'";

$result2= mysql_query($query2);

  $count2= mysql_num_rows($result2);

if($count2==0){

header("location: login.php"); $_SESSION['message']="Wrong

Username/Password"; exit; };

};

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.