Current location: Hot Scripts Forums » Programming Languages » PHP » there is suddenly an error...wat the...


there is suddenly an error...wat the...

Reply
  #1 (permalink)  
Old 07-13-05, 03:48 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
there is suddenly an error...wat the...

the login was working perfectly all right when it was in my com, but when i transferred it to another com, there were errors:

Notice: Undefined index: UserID in c:\inetpub\wwwroot\Merge\login_process.php on line 10

Notice: Undefined index: Password in c:\inetpub\wwwroot\Merge\login_process.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\Merge\login_process.php:10) in c:\inetpub\wwwroot\Merge\login_process.php on line 37

my codes for displaying:
Code:

<form name="login" method="post" action="login_process.php">
<table width="39%" border="0" align="center" bordercolor="#FFFFFF">
<tr>
<td>UserID</td>
<td><input name="UserID" type="text" id="UserID5"></td>
</tr>
<tr>
<td>Password</td>
<td><input name="Password" type="password" id="Password4"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input name="Login" type="submit" id="Login4" value="Login">
</div></td>
</tr>
</table>
</form>



and the codes that does the processing:
Code:

session_start();
include("database.php");

$sql = "SELECT * from User
WHERE UserID='$_POST[UserID]'
AND Password='$_POST[Password]'";
$result = mysql_query($sql)
or die ("couldnt execute query.");
$num = mysql_num_rows($result);
if ($num == 1) //login name and password match
{
$sql = "SELECT AccessLevel from User
WHERE UserID='$_POST[UserID]'";
$result2 = mysql_query($sql)
or die ("couldnt execute query 2.");
$value = mysql_result($result2,0);
if ($value == 1) //AccessLevel is 1
{
$logname=$_POST['UserID'];
$_SESSION['logname'] = $logname;
header("Location: report_form_admin.php");
}
else //AccessLevel is 3
{
$logname=$_POST['UserID'];
$_SESSION['logname'] = $logname;
header("Location: report_form.php");
}
}
elseif ($num == 0) //login name and password do not match
{
header("Location: login_form_error.php");

}
Reply With Quote
  #2 (permalink)  
Old 07-13-05, 03:58 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
i seem to find out the problem, all my codes that have $_POST[var] cant work and have errors in them. Is there anyway i can solve the problem? we are all using the same versions of php and mysql. can some1 help? its quite urgent. thx in advance! =)
Reply With Quote
  #3 (permalink)  
Old 07-13-05, 04:01 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
change:

$sql = "SELECT * from User
WHERE UserID='$_POST[UserID]'
AND Password='$_POST[Password]'";

to:

$sql = "SELECT * from User
WHERE UserID='{$_POST[UserID]}'
AND Password='{$_POST[Password]}'";
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #4 (permalink)  
Old 07-13-05, 04:09 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
$_POST[UserID]

you cant do that

it has to be

$_POST["UserID"]
Reply With Quote
  #5 (permalink)  
Old 07-13-05, 04:16 AM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
To perleo:

Yes, he can! It is perfectly legal inside a literal; moreover, PHP will regard UserID as a constant with the value of 'UserID' (with a notice) - however, this is bad programming practice to use unquoted string literals.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #6 (permalink)  
Old 07-18-05, 01:35 PM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by phplearner
i seem to find out the problem, all my codes that have $_POST[var] cant work and have errors in them. Is there anyway i can solve the problem? we are all using the same versions of php and mysql. can some1 help? its quite urgent. thx in advance! =)
The two "notice" messages are due to trying to use a variable that does not exist. It may sound strange since $_POST is a global variable but the slice of array is not available...

The other error is due to the header() funcation being used after something has been sent to the web browser.

Hope this helps.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.