Link to home
Start Free TrialLog in
Avatar of 7704300
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\userlogin.php on line 3

Warning: Undefined variable: _POST in c:\phpdev\www\helpdesk\userlogin.php on line 3

Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\userlogin.php:3) in c:\phpdev\www\helpdesk\userlogin.php on line 4


************************************************************************************

Also here is my code!

<?php
//check for required fields from the form
if ((!$_POST[Num_Login_Details_ID]) || (!$_POST[String_Login_Details_Pswd])) {
      header("Location: userlogin.html");
      exit;
}

//connect to server and select database
$conn = mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("project_client_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_Login_Details_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\">secret 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>

Avatar of Roonaan
Roonaan
Flag of Netherlands image

Change your start to:

<?php
//check for required fields from the form
if( $_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST['Num_Login_Details_ID']) || empty($_POST['String_Login_Details_Pswd'])) {
     header("Location: userlogin.html");
     exit;
}

-r-
Avatar of 7704300
7704300

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_Details_ID']) || empty($_POST['String_Login_Details_Pswd'])) { header("Location: userlogin.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("project_client_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_Login_Details_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:
&#61623; 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\userlogin.php on line 46//check for required fields from the form if( $_SERVER['REQUEST_METHOD'] != 'POST' || empty($_POST['Num_Login_Details_ID']) || empty($_POST['String_Login_Details_Pswd'])) { header("Location: userlogin.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("project_client_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_Login_Details_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:
&#61623; 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\userlogin.php on line 46
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-
Avatar of 7704300

ASKER

Doesnt this line cover that?

 header("Location: userlogin.html");


What do you think I should do?

Thanks for the help btw : )

Avatar of 7704300

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\userlogin.php on line 3

Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\helpdesk\userlogin.php:3) in c:\phpdev\www\helpdesk\userlogin.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_Details_ID']) || empty($_POST['String_Login_Details_Pswd'])) {
     header("Location: userlogin.html");
     exit;
}
which php version are you running??

-r-
Avatar of 7704300

ASKER

I think I'm running on php 4.0.6  Is this a problem?
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 7704300

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!