7704300
asked on
Use of undefined constant
Hi
When tryin to create my first php login page(it connects to a mySQL db) I get the following errors. Can anyone help?
Thank you
Warning: Use of undefined constant Num_Login_Details_ID - assumed 'Num_Login_Details_ID' in c:\phpdev\www\helpdesk\use rlogin.php on line 3
Warning: Undefined variable: _POST in c:\phpdev\www\helpdesk\use rlogin.php on line 3
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\use rlogin.php :3) in c:\phpdev\www\helpdesk\use rlogin.php on line 4
************************** ********** ********** ********** ********** ********** ********
Also here is my code!
<?php
//check for required fields from the form
if ((!$_POST[Num_Login_Detail s_ID]) || (!$_POST[String_Login_Deta ils_Pswd]) ) {
header("Location: userlogin.html");
exit;
}
//connect to server and select database
$conn = mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("project_c lient_db", $conn) or die(mysql_error());
//create and issue the query
$sql = "select Num_Login_Details_ID from login_details
where Num_Login_Details_ID = '$_POST[Num_Login_Details_ ID]' AND String_Login_Details_Pswd = password('$_POST[String_Lo gin_Detail s_Pswd]')" ;
$result = mysql_query($sql,$conn) or die(mysql_error());
//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {
//if authorized, get the values of Num_Login_Details_ID
$f_name = mysql_result($result, 0, 'Num_Login_Details_ID');
//create display string
$display_block = "<P>$Num_Login_Details_ID is authorized!</p>
<P>Authorized Users' Menu:
<ul>
<li><a href=\"secretpage.php\">se cret page</a>
</ul>";
} else {
//redirect back to login form if not authorized
header("Location: userlogin.html");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>User Login</TITLE>
</HEAD>
<BODY>
<? echo "$display_block"; ?>
</BODY>
</HTML>
When tryin to create my first php login page(it connects to a mySQL db) I get the following errors. Can anyone help?
Thank you
Warning: Use of undefined constant Num_Login_Details_ID - assumed 'Num_Login_Details_ID' in c:\phpdev\www\helpdesk\use
Warning: Undefined variable: _POST in c:\phpdev\www\helpdesk\use
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\use
**************************
Also here is my code!
<?php
//check for required fields from the form
if ((!$_POST[Num_Login_Detail
header("Location: userlogin.html");
exit;
}
//connect to server and select database
$conn = mysql_connect("localhost",
mysql_select_db("project_c
//create and issue the query
$sql = "select Num_Login_Details_ID from login_details
where Num_Login_Details_ID = '$_POST[Num_Login_Details_
$result = mysql_query($sql,$conn) or die(mysql_error());
//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {
//if authorized, get the values of Num_Login_Details_ID
$f_name = mysql_result($result, 0, 'Num_Login_Details_ID');
//create display string
$display_block = "<P>$Num_Login_Details_ID is authorized!</p>
<P>Authorized Users' Menu:
<ul>
<li><a href=\"secretpage.php\">se
</ul>";
} else {
//redirect back to login form if not authorized
header("Location: userlogin.html");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>User Login</TITLE>
</HEAD>
<BODY>
<? echo "$display_block"; ?>
</BODY>
</HTML>
ASKER
Thanks for the quick response. I tried that and now the following. Sorry I'm very new to this!
//check for required fields from the form if( $_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST['Num_Login_De tails_ID'] ) || empty($_POST['String_Login _Details_P swd'])) { header("Location: userlogin.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("project_c lient_db", $conn) or die(mysql_error()); //create and issue the query $sql = "select Num_Login_Details_ID from login_details where Num_Login_Details_ID = '$_POST[Num_Login_Details_ ID]' AND String_Login_Details_Pswd = password('$_POST[String_Lo gin_Detail s_Pswd]')" ; $result = mysql_query($sql,$conn) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of Num_Login_Details_ID $f_name = mysql_result($result, 0, 'Num_Login_Details_ID'); //$l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie //setcookie("auth", "1", 0, "/", "yourdomain.com", 0); //create display string $display_block = "
$Num_Login_Details_ID is authorized!
Authorized Users' Menu:
 secret page
"; } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
Warning: Undefined variable: display_block in c:\phpdev\www\helpdesk\use rlogin.php on line 46//check for required fields from the form if( $_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST['Num_Login_De tails_ID'] ) || empty($_POST['String_Login _Details_P swd'])) { header("Location: userlogin.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("project_c lient_db", $conn) or die(mysql_error()); //create and issue the query $sql = "select Num_Login_Details_ID from login_details where Num_Login_Details_ID = '$_POST[Num_Login_Details_ ID]' AND String_Login_Details_Pswd = password('$_POST[String_Lo gin_Detail s_Pswd]')" ; $result = mysql_query($sql,$conn) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of Num_Login_Details_ID $f_name = mysql_result($result, 0, 'Num_Login_Details_ID'); //$l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie //setcookie("auth", "1", 0, "/", "yourdomain.com", 0); //create display string $display_block = "
$Num_Login_Details_ID is authorized!
Authorized Users' Menu:
 secret page
"; } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
Warning: Undefined variable: display_block in c:\phpdev\www\helpdesk\use rlogin.php on line 46
//check for required fields from the form if( $_SERVER['REQUEST_METHOD']
$Num_Login_Details_ID is authorized!
Authorized Users' Menu:
 secret page
"; } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
Warning: Undefined variable: display_block in c:\phpdev\www\helpdesk\use
$Num_Login_Details_ID is authorized!
Authorized Users' Menu:
 secret page
"; } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
Warning: Undefined variable: display_block in c:\phpdev\www\helpdesk\use
It seems that your header("Location: userlogin.html"); is not called. But I don't see a headers-allready-sent warning in your last post.
-r-
-r-
ASKER
Doesnt this line cover that?
header("Location: userlogin.html");
What do you think I should do?
Thanks for the help btw : )
header("Location: userlogin.html");
What do you think I should do?
Thanks for the help btw : )
ASKER
Hi,
I had missed something really obivous, Sorry about that . This what I've got now. Can anyone help?
Warning: Undefined variable: _SERVER in c:\phpdev\www\helpdesk\use rlogin.php on line 3
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\use rlogin.php :3) in c:\phpdev\www\helpdesk\use rlogin.php on line 4
I believe these are the lines being referred to
<?php
//check for required fields from the form
if( $_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST['Num_Login_De tails_ID'] ) || empty($_POST['String_Login _Details_P swd'])) {
header("Location: userlogin.html");
exit;
}
I had missed something really obivous, Sorry about that . This what I've got now. Can anyone help?
Warning: Undefined variable: _SERVER in c:\phpdev\www\helpdesk\use
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\use
I believe these are the lines being referred to
<?php
//check for required fields from the form
if( $_SERVER['REQUEST_METHOD']
header("Location: userlogin.html");
exit;
}
which php version are you running??
-r-
-r-
ASKER
I think I'm running on php 4.0.6 Is this a problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Whoops! My computer already had PHP, Apache and MySQl from when my brother used it So I figured if it aint broke dont fix it. Little did I know it WAS broke : )
Thanks for your help R - as someone once said - I'LL BE BACK!!!!!
Thanks again!
Thanks for your help R - as someone once said - I'LL BE BACK!!!!!
Thanks again!
<?php
//check for required fields from the form
if( $_SERVER['REQUEST_METHOD']
header("Location: userlogin.html");
exit;
}
-r-