Jump to content


Photo

Help me plz....


  • Please log in to reply
7 replies to this topic

#1 irin07

irin07
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 October 2006 - 08:43 AM


i dont what's wrong with my code

$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

keep repeating that the error is undefined variable

thanks

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 06 October 2006 - 08:55 AM

If no data has been sent to the page then the $_POST variables are not defined

try
<?php
$myusername= isset($_POST['myusername']) ? $_POST['myusername'] : '';
$mypassword= isset($_POST['mypassword']) ? $_POST['mypassword'] : '';

?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 irin07

irin07
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 October 2006 - 09:19 AM

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
<?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>



stafflog2.php

<?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>


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

?>


login_success.php

<? 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>


thanks

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 06 October 2006 - 09:28 AM

but still there's an error


What error message?
What file?
What isn't it doing that it should do?
What is it doing that it shouldn't do?

Don't just post code and say "This doesn't work" if you expect help.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 irin07

irin07
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 October 2006 - 09:42 AM

the error is in checklogin.php
say that undefined variable:mypassword

sorry,cause im dont really understand php,just beginner

#6 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 10:00 AM

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

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 October 2006 - 10:35 AM

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

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

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

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

to the following:
$mypassword  =isset($_POST['mypassword']) ? $_POST['mypassword'] :'';


#8 irin07

irin07
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 October 2006 - 11:32 AM

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 the page cannot be found

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

thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users