PHP Variable Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

PHP Variable Problem

Post by phppick »

Hi I am getting error with PHP variable,here i am giving all files. pls go through it. PLs clear my Problem . TQ


-----error.htm-----------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0032)http://localhost/Test/login.php -->
<HTML><HEAD><TITLE>Some Login</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0><BR><B>Notice</B>:
Undefined index: userid in <B>C:\Documents and
Settings\Administrator\Desktop\Test\login.php</B> on line
<B>7</B><BR><BR><B>Notice</B>: Undefined index: password in <B>C:\Documents and
Settings\Administrator\Desktop\Test\login.php</B> on line
<B>8</B><BR><BR><B>Notice</B>: Undefined index: error in <B>C:\Documents and
Settings\Administrator\Desktop\Test\login.php</B> on line <B>12</B><BR>
<FORM id=frmLogin name=frmLogin action=login.php method=post>
<TABLE height=400 cellSpacing=1 cellPadding=1 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=left height=17>
<TABLE cellSpacing=0 cellPadding=0 width=393 align=center border=0>
<TBODY>
<TR>
<TD vAlign=top align=left>
<DIV align=center></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=393 align=center border=0>
<TBODY>
<TR vAlign=top align=left>
<TD width=393></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=393 align=center border=0>
<TBODY>
<TR vAlign=top align=left>
<TD width=393></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=393 align=center border=0>
<TBODY>
<TR vAlign=top align=left>
<TD width=393>
<TABLE cellSpacing=0 cellPadding=0 width=393 align=center
border=0><TBODY>
<TR>
<TD vAlign=top align=left width=358></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=4 cellPadding=0 width=393 border=0>
<TBODY>
<TR>
<TD vAlign=top align=left>
<DIV align=center><FONT
face="Verdana, Arial, Helvetica, sans-serif" size=1><B><FONT
color=#ffffff>Enter your username and password :
</FONT></B></FONT></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=4 cellPadding=0 width=300 align=center
border=0><TBODY>
<TR align=left>
<TD vAlign=top width=90>
<DIV align=right><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2><B>Username :</B></FONT></DIV></TD>
<TD vAlign=top><INPUT class=mystyle3 maxLength=10 size=14
name=userid> </TD></TR>
<TR align=left>
<TD vAlign=top>
<DIV align=right><FONT
face="Verdana, Arial, Helvetica, sans-serif"
size=2><B>Password :</B></FONT></DIV></TD>
<TD vAlign=bottom><INPUT class=mystyle3 type=password
maxLength=10 size=14 name=password> <INPUT type=submit value=" Login " name=submit> </TD></TR>
<TR align=left>
<TD vAlign=top>&nbsp;</TD>
<TD vAlign=top align=middle>
<DIV
align=left></DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><BR><B>Notice</B>:
Undefined index: error in <B>C:\Documents and
Settings\Administrator\Desktop\Test\login.php</B> on line
<B>152</B><BR></BODY></HTML>
-----END error.htm-----


**************PHP FILES***************************************
-------login.php----

<?

include_once ('httpio.inc');
include_once ('db.inc');

$formVars = HttpPrm();
$userid = $formVars["userid"];
$password = $formVars["password"];

session_start();

if ($formVars["error"]=="")
{
if ($userid && $password) // if the user has just tried to log in
{
$result = mysql_query("select user, pwd from login where user='".$userid."'");
if (!$result)
{
logError("Login.php:" . mysql_error());
gotoPage("login.php?error=0");
exit;
}
if (mysql_num_rows($result) > 0)
{
// if they are in the database register the user id
$detail = mysql_fetch_array($result);
if (md5($password) == $detail["pwd"])
{
$__session_id = session_id();
$__session_pw = $password;
$__session_start_time = date("U");
$__session_user = $detail["user"];
$sv_SessionUser = $__session_user;
$__session_start_time = date("U");
mysql_free_result($result);
session_register("__session_id", "__session_pw", "__session_user", "__session_start_time");
session_register("sv_SessionUser","sv_UserType");

if ($__session_user == "Admin")
jScript("top.location = 'redirect.php';");
else
{
session_destroy();
logError("Login.php: Invalid User type");
gotoPage("login.php?error=1");
exit;
}
exit;
}
else
{
session_destroy();
gotoPage("login.php?error=2");
exit;
}
}
else
{
if (isset($userid))
{
logError("Login.php: Failed login :". $userid);
gotoPage("login.php?error=3");
exit;
}
}
}
}
?>

<html>
<head>
<title>Some Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="frmLogin" id="frmLogin" method=post action="login.php">
<table width="100%" border="0" cellspacing="1" cellpadding="1" height="400">
<tr>
<td height="17" align="left" valign="top">
<table width="393" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" valign="top">
<div align="center"></div>
</td>
</tr>
</table>
<table width="393" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="left" valign="top">
<td width="393"></td>
</tr>
</table>
<table width="393" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="left" valign="top">
<td width="393"></td>
</tr>
</table>
<table width="393" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="left" valign="top">
<td width="393">
<table width="393" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left" valign="top" width="358">

</td>
</tr>
</table>
<table width="393" border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="left" valign="top">
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#FFFFFF">Enter your username and password : </font></b></font></div>
</td>
</tr>
</table>
<table width="300" border="0" cellspacing="4" cellpadding="0" align="center">
<tr align="left">
<td width="90" valign="top">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Username
:</b></font></div>
</td>
<td valign="top">
<input type="text" name=userid class="mystyle3" size="14" maxlength="10">
</td>
</tr>
<tr align="left">
<td valign="top">
<div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Password
:</b></font></div>
</td>
<td valign="bottom">
<input type=password name=password class="mystyle3" size="14" maxlength="10">
<input type="submit" name="submit" value=" Login ">
</td>
</tr>
<tr align="left">
<td valign="top">&nbsp;</td>
<td align="center" valign="top">
<div align="left"></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>

<?
if ($formVars["error"]!="")
{
switch ($formVars["error"])
{
case '0':
alert("No Communication with the server. Please try again later.");
break;
case '1':
alert("You Login info is invalid. Please inform your System Admin.");
break;
case '2':
alert("Password is Invalid. Please try again");
break;
case '3':
alert ("User name or password are Invalid . Please Try again.");
break;
}
}

?>
----END login.php---

---db.inc---
<?php

$db="database";
$db_conn = mysql_connect("localhost","root","")
or die("Could not connect to database");


mysql_select_db($db, $db_conn)
or die("Could not select $db database");

?>
--end db.inc---

----httpio.inc--
<?

function HttpPrm( )
{
global $HTTP_GET_VARS,$HTTP_POST_VARS,$HttpPost;

if ( count($HTTP_POST_VARS) ) return ( $HTTP_POST_VARS );
if ( count($HTTP_GET_VARS) ) return ( $HTTP_GET_VARS );
return ( $HTTP_POST_VARS );
}

function HttpVar( $vKey )
{
global $HTTP_GET_VARS,$HTTP_POST_VARS,$HttpPost;

if ( count($HTTP_POST_VARS) ) return ( $HTTP_POST_VARS[$vKey] );
if ( count($HTTP_GET_VARS) ) return ( $HTTP_GET_VARS[$vkey] );
return ( $HTTP_POST_VARS[$vkey] );
}

function CvtAsc2Htm( $sSrc )
{
global $sHtmLst,$sAscLst;
return ( str_replace($sAscLst,$sHtmLst,$sSrc) );
}

function CvtHtm2Asc( $sSrc )
{
global $sHtmLst,$sAscLst;
return ( str_replace($sHtmLst,$sAscLst,$sSrc) );
}

?>

--end httpio.inc---
User avatar
Seth_[php.pl]
Forum Commoner
Posts: 30
Joined: Sun Aug 10, 2003 5:25 am
Location: Warsaw / Poland

Post by Seth_[php.pl] »

Another spamer :P
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

yup
shame this isnt a 'please fix' forum
course posting it in 2 different forums doesnt help any :roll:
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

phppick: I know it's your first time here so let me explain a bit about the forums.

First off, pick the correct forum for your post - and don't post the same message in several forums. This forum is for advanced subjects not basic queries: you want the normal forum.

That was a huge chunk of code you posted - and none of it was highlighted with php tags. We're all busy on our own projects so you're much more likely to get a response if you can narrow the problem down to a single block of code (and add syntax highlighting it so we can read it more easily). We expect people to at least make an effort to fix their own code first.

Finally, a useful debugging tip is to echo $vars or print_r arrays to check that the vars you expect exist where you think they should be, and with the correct values. Comment the lines on and off while you're debugging.
Locked