Jump to content

Help me plz....


irin07

Recommended Posts

but still there's an error
i try to create a login in php

maybe u can try to find what is the error in this code


stafflog.php
[code]
<?php
require ("helplib.php");
connectdb();

session_start();
session_destroy();

?>

<html>
<head>
<title>Staff and Tickets Information</title>
<link rel="stylesheet" type="text/css" href="helpstyle.css">

<head>

<body>
<center>

<?php heading ("Staff and Tickets Information"); ?>

<br>
<table width="70%" border="2" cellspacing="6" cellpadding="15" bordercolor="#660066">
<tr align="center">
    <td><h2><a href="staff2.php">Staff Information</a></td>
</tr>
<tr align="center">
    <td><h2><a href="tickets2.php">Tickets Information</h2></a></td>
</tr>
</table>
</form>
</center>
<br><br>

<a href="index.php">Log out</a>

<?php footer (); ?>
</body>
</html>


[/code]

stafflog2.php

[code]<?php
require ("helplib.php");
connectdb();

session_start();
session_destroy();

?>

<html>
<head>
<title>Staff and Tickets Information</title>
<link rel="stylesheet" type="text/css" href="helpstyle.css">

<head>

<body>
<center>

<?php heading ("Staff and Tickets Information"); ?>

<br>
<table width="70%" border="2" cellspacing="6" cellpadding="15" bordercolor="#660066">
<tr align="center">
    <td><h2><a href="staff2.php">Staff Information</a></td>
</tr>
<tr align="center">
    <td><h2><a href="tickets2.php">Tickets Information</h2></a></td>
</tr>
</table>
</form>
</center>
<br><br>

<a href="index.php">Log out</a>

<?php footer (); ?>
</body>
</html>

[/code]

checklogin.php
[code]<?php

$host="localhost";
$staffID="root";
$password="tmc";
$db_name="dbhelpdesk";
$tbl_name="tblstaff";

mysql_connect("$host", "$staffID", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$mystaffID =isset($_POST['mystaffID']) ? $_POST['mystaffID'] :'';
$password  =isset($_POST['mypassword']) ? $_POST['mypassword'] :'';

$sql ="SELECT * FROM $tbl_name WHERE staffID='$mystaffID' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if ($count==1){
session_register("mystaffID");
    session_register("mypassword");
header("location:login_success.php");
}
else{
echo"Valid staffID or password";
    }
   

?>

[/code]

login_success.php

[code]
<? php
session_start();
if(!session_is_registered(mystaffID))
?>

<html>
<head>
<title>Check</title>
</head>
<body>
<a href="stafflog2.php">Go To List </a>

Login Successful
</body>
</html>

[/code]

thanks
Link to comment
Share on other sites

from where you are getting the username and password

when the user click the submit button then you retrive the value


if(isset($_post['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];


$sql ="SELECT * FROM $tbl_name WHERE staffID='$username' and password='$password' ";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if ($count==1){
session_register("mystaffID");
    session_register("mypassword");
header("location:login_success.php");
}
else{
echo"Valid staffID or password";
    }
}

try this
Link to comment
Share on other sites

The error is to do with this:
[code=php:0]$password  =isset($_POST['mypassword']) ? $_POST['mypassword'] :'';

$sql ="SELECT * FROM $tbl_name WHERE staffID='$mystaffID' and password='$mypassword'";[/code]

Notice in your query you use a variable called [b]mypassword[/b]. However you save the mypassword POST var ($_POST['mypassword']) in a variable called [b]password[/b]

So change the following line:
[code=php:0]$password  =isset($_POST['mypassword']) ? $_POST['mypassword'] :'';[/code]

to the following:
[code=php:0]$mypassword  =isset($_POST['mypassword']) ? $_POST['mypassword'] :'';[/code]
Link to comment
Share on other sites

password and staffID actually must be found in tblStaff (in database mysql)

so when i click 'submit' , it would retrive to tblStaff,

if correct,it will show the tblstaff,if not then show valid staffid and pasword

now the error is when i click 'submit' the error msg say that [u]the page cannot be found[/u]

and if i want to put session variable for password and staffID, where should i put the code???

thanks
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.