Jump to content

Recommended Posts

I've followed every single step, made every single file, but I don't know why it's not working. It might be that I haven't named the files right, or just didn't make the right file. Could you guys help me out?

 

Index.php:

<?php
/* File: login_reg_form.inc
* Desc: Contains the code for a Web page that displays
*	 two HTML forms, side by side. One is a login
*	 form, and the second is a registration form.
*/
include("functions.inc");
?>
<head><title>Customer Login Page</title>
<style type='text/css'>
  <!--
  label {
   font-weight: bold;
   float: left;
   width: 27%;
   margin-right: .5em;
   }
  legend {
   font-weight: bold;
   font-size: 1.2em;
   margin-bottom: .5em;
  #wrapper {
   margin: 0;
   padding: 0;
   }
  #login {
   position: absolute;
   left: 0;
   width: 40%;
   padding: 1em 0;
   }
  #reg {
   position: absolute;
   left: 40%;
   width: 60%;
   padding: 1em 0;
   }
  #feild {padding-bottom: .5em;}
  .errors {
   font-weight: bold;
   font-style: italic;
   font-size: 90%;
   color: red;
   margin-top: 0;
   }
  -->
</style>
</head>
<body style="margin: 0">
<?php
$fields_1 =	array("fusername" => "User Name", "fpassword" => "Password");
$fields_2 = array("user_name" => "User Name", "password" => "Password", "email" => "Email", "first_name" => "First Name", "last_name"	=> "Last Name", "street" => "Street", "city" => "City", "state" => "State", "zip" => "Zip", "phone" => "Phone", "fax" => "Fax" );
?>
<div id="wrapper">
  <div id="login">
   <form action=<?php echo $_SERVER['PHP_SELF']?>
method="POST">
      <fieldset style='border: 2px solid #000000'>
        <legent>Login Form</legent>
<?php
if (isset($message_1))
{
  echo "<p class='errors'>$message_1</p>\n";
}
foreach($fields_1 as $field => $value)
{
  if(preg_match("/pass/i",$field))
    $type = "text";
  else
    $type = "text";
  echo "<div id='field'>
    <label for='$field'>$value</label>
    <input id='$field' name='$field' type='$type'
    value='".@$$field."' size='20' maxlength='50' />
    </div>\n";
}
?>
<input type="submit" name="Button"
       stype='margin-left: 45%; margin-bottom: .5em'
      </fieldset>
    </form>
    <p style='text-align: center; margin: 1em'>
If you already have an account, log in.</p>
    <p style='text-align: center; margin: 1em'>
If you do not have an account, register now.</p>
  </div>
  <div id="reg">
    <form action=<?php echo $_SERVER['PHP_SELF']?>
  method="POST">
      <fieldset style='border: 2px solid #000000'>
       <legend>Registration Form</legend>
<?php
if(isset($message_2))
{
  echo "<[ class='errors'>$message_2</p>\n";
}
foreach($fields_2 as $field => $value)
{
  if($field == "state")
  {
    echo "<div id='field'>
      <label for='$field'>$value</label>
      <select name='state' id='state'>";
      $stateName=getStateName();
      $stateCode=getStateCode();
      for ($n=1;$n<=50;$n++)
      {
	$state=$stateName[$n];
	$scode=$stateCode[$n];
	echo "<option value='$scode'";
	if ($scode== "AL")
	    echo " selected";
	echo ">$state</option>\n";
      }
      echo"</select></div>";
  }
  else
  {
    if(preg_match("/pass/i",$field))
      $type = "password";
    else
      $type = "text";
    echo "<div id='field'>
      <label for=$field'>$value</label>
      <input id=$field' name='$field' type='$type'
      value='".@$$field."' size='40' maxlength='65' />
      </div>\n";
   } //end else
} // end foreach field
?>
<input type="submit" name="Button"
    style='margin-left: 45%; margin-bottom: .5em'
    value="Register">
      </fieldset>
    </form>
  </div>
</div>
</body></html>

 

Login_reg.php:

<?php
/* Program: 	Login_reg.php
* DESC: 	Main application script for the User Login
*		application. It provides two options: (1) login
*		using an existing User Name and (2) register
*		a new username. User Names and passwords are 
*		stored in MySQL database.
*/
session_start();
switch (@$_POST['Button'])
{
  cast "Login":
    include("dbstuff.inc");
    $cxn = mysqli_connect($host,$user,$password,$database)
   		or die("Query died: connect:);
    $sql = "SELECT user_name FROM Customer
    		 WHERE user_name='$_POST[fusername]'";
    $result = mysqli_query($cxn,$sql)
  		   or die("Query died: fuser_name");
    $num = mysqli_num_rows($result);
    if($num > 0)
    {
      $sql = "SELECT user_name FROM Customer
	 WHERE user_name='$_POST[fusername]'
	 AND password=md5('$_POST[fpassword]')";
      $result2 = mysqli_query($cxn,$sql)
	or die("Query died: fpassword");
      $num2 = mysqli_num_rows($result2);
      if($num2 > 0) //password matches
      {
        $_SESSION['auth'="yes";
  $_SESSION['logname'] = $_POST['fusername'];
  header("Location: SecretPage.php");
      }
else // password does not match
{
  $message_1="The Login Name, '$_POST[fusername]'
	esists, but you have not entered the correct password! Please try again.";
  $fusername = strip_tags(trim($_POST[fusername]));
  include("form_login_reg.inc");
}
    } // end if $num > 0
    elseif($num == 0) // login name not found
    {
$message_1 = "The User Name you entered does not exist! Please try again.";
include("form_login_reg.inc");
    }
  break;

  cast "Register":
    /* Check for blanks */
    foreach($_POST as $field => $value)
    {
      if ($field != "fax")
{
  $blanks[] = $field;
}
else
{
  $good_data[$field = strip_tags(trim($value));
}
    }
  } // end foreach POST
  if(isset($blanks))
  {
$message_2 = "The following fields are blank. Please enter the required information: ";
foreach($blanks as $value)
{
	 $message_2 .="$value, ";
}
extract($good_data);
include("form_login_reg.inc")
exit();
} // end if blanks found
/* validate data*/
foreach($_POST as $field => $value)
{
	if(!empty($value))
	{
		if(preg_match("/name/i",$field) and !preg_match("/user/i",$field) and !preg_match("/log/i",$field)) {
			if (!preg_match("/^[A-Za-z' -]{1,50}$/",$value)){
				$errors[] = "$value is not a valid name. ";
				}
			}
			if(preg_match("/street/i",$field) or preg_match("/addr/i",$field) or preg_match("/city/i",$field)){
				if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",$value)){
					$errors[] = "$value is not a valid address or city";
				}
			}
			if(preg_match("/state/i",$field)){
				if(!preg_match("/^[A-Z][A-Z]$/",$value)){
					$errors[] = "$value is not a valid state code. ";
				}
			}
			if(preg_match("/email/i",$field)){
				if(!preg_match("/^.+@.+\\..+$/",$value)){
					$errors[] = "$value is not a valid email address. ";
				}
			}
			if(preg_match("/zip/i",$field)){
				if(!preg_match("/^[0-9]{5,5}(\-[0-9]{4,4})?$/",$value)){
					$errors[] = "$value is not a valid zipcode. ";
				}
			}
			if(preg_match("/phone/i",$field) or preg_match("/fax/i",$field)){
				if(!preg_match("/^[0-9) (xX -]{7,20}$/",$value)){
					$errors[] = "$value is not a valid phone number. ";
				}
			}
		} // end if not empty
	} // end foreach POST
	foreach($_POST as $field => $value)){
		$$field = strip_tags(trim($value));
	}
	if(@is_array($errors)){
		$message_2 = "";
		foreach($errors as $value){
			$message_2 .= $value." Please try again<br />";
		}
		include("form_login_reg.inc");
		exit()
	} // end if errors are found

	/* check to see if user name already exists */
	include("dbstuff.inc");
	$cxn = mysqli_connect($host,$user,$password,$database) or die("Couldn`t connect to server");
	$sql = "SELECT user_name FROM Customer WHERE user_name='$user_name'";
	$result = mysqli_query($cxn,$sql) or die("Query died: user_name");
	$num = mysqli_num_rows($result);
	if($num > 0)
	{
		$message_2 = "user_name already used. Select another User Name.";
		include("form_login_reg.inc");
		exit();
	} // end if user name already exists
	else{
		$today = date("Y-m-d");
		$sql = INSERT INTO Customer (user_name,create_date,password,first_name,last_name,street,city,state,zip,phone,fax,	  email) VALUES('$user_name','$today',md5('$password'),'$first_name', '$last_name','$street','$city','$state','$zip','$phone',' $fax','$email')";
		mysqli_query($cxn,$sql);
		$_SESSION['auth']="yes";
		$_SESSION['logname'] = $user_name;
		/* send email to new Customer */
		$emess = "You have successfully registered. ";
		$emess .= "You have successfully registered. ";
		$emess .= "\n\n\t$user_name\n\t";
		$emess .= "$password\n\n";
		$emess .= "We appreciate your interest. \n\n";
		$emess .= "If you have any questions or problems,";
		$emess .= " email service@ourstore.com";
		$subj = "Your new customer registration";
		$mailsend=mail("$email","$subj","$emess");
		header("Location: SecretPage.php);
	} // end else no errors found
break;

default:
	include("form_login_reg.inc");
} // end switch
?>	

 

functions.inc:

<?php
function getStateCode(){
$stateCode = array(1=> "AL","AK","AZ","FL","NJ","NY","WY");
return $stateCode;
}

function getStateName(){
$stateName = array(1=> "Alabama","Alaska","Arizona","Florida","New Jersey","New York","Wyoming");
return $stateName;
}
?>

 

dbstuff.inc:

<?php
$host = "localhost";
$user = "root";
$password = "xxxxxxx";
$database = "CustomerDirectory";
?>

 

form_login_reg.inc:

foreach($fields_1 as $field => $value){
if(preg_match("/pass/i",$field))
  $type = "password";
else
  $type = "text";
echo "<div id='field'>
  <label for='$field'>$value</label>
  <inlut id='$field' name='$field' type='$type' value='"@$$field."' size='20' maxlength='15' />
</div>\n";
}

 

SecretPage.php:

<?php
/* File: SecretPage.php
  * Desc: Displays a welcome page when the user successfully logs in or registers.
  */
session_start();
if(@$_SESSION['auth'] != "yes"){
header("Location: Login_reg.php");
exit();
}
echo "<head><title>Secret Page</title></head><body>";
echo "<p style='text-align: center; font-size: 1.5em; font-weight: bold; margin-top: 1em'>The User ID, {$_SESSION['logname']},has successfully logged in</p>";
?>
</body></html> 

 

 

I have the files uploaded to my wamp server: http://69.122.127.213

I've followed every single step, made every single file, but I don't know why it's not working. It might be that I haven't named the files right, or just didn't make the right file. Could you guys help me out?

 

This is not enough info for us to help you. We need errors, what its supposed to do, what its not doing... etc.

 

 

I've followed every single step, made every single file, but I don't know why it's not working. It might be that I haven't named the files right, or just didn't make the right file. Could you guys help me out?

 

This is not enough info for us to help you. We need errors, what its supposed to do, what its not doing... etc.

 

Okay. What it's supposed to do is:

1) Have a login/register page.

2) If you don't have an account, register one with the register table, and send the information to the MySQL Database.

3) When you have an account, be able to login, and see SecretPage.php

 

What it's not doing:

1) When I click register, nothing happens, and nothing is sent to the database

2) When I click login, it doesn't say: This username doesn't exist.

In Login_reg, you are missing an end quote here

 

or die("Query died: connect:);

 

You'll just have to go through your code and find errors like this.  It will help if you turn on error reporting and display errors also.

In Login_reg, you are missing an end quote here

 

or die("Query died: connect:);

 

You'll just have to go through your code and find errors like this.  It will help if you turn on error reporting and display errors also.

 

Okay. Where does that end quote go? And I'm using PHP Designer 2007 - Personal. I got it from the Editor section. Does that have highlight errors?

PHP Designer is pretty good, so you should see syntax highlighting automatically.

 

 

 

Okay. Where does that end quote go? And I'm using PHP Designer 2007 - Personal. I got it from the Editor section. Does that have highlight errors?

I've followed every single step, made every single file, but I don't know why it's not working. It might be that I haven't named the files right, or just didn't make the right file. Could you guys help me out?

 

Index.php:

<?php
/* File: login_reg_form.inc
* Desc: Contains the code for a Web page that displays
*	 two HTML forms, side by side. One is a login
*	 form, and the second is a registration form.
*/
include("functions.inc");
?>
<head><title>Customer Login Page</title>
<style type='text/css'>
  <!--
  label {
   font-weight: bold;
   float: left;
   width: 27%;
   margin-right: .5em;
   }
  legend {
   font-weight: bold;
   font-size: 1.2em;
   margin-bottom: .5em;
  #wrapper {
   margin: 0;
   padding: 0;
   }
  #login {
   position: absolute;
   left: 0;
   width: 40%;
   padding: 1em 0;
   }
  #reg {
   position: absolute;
   left: 40%;
   width: 60%;
   padding: 1em 0;
   }
  #feild {padding-bottom: .5em;}
  .errors {
   font-weight: bold;
   font-style: italic;
   font-size: 90%;
   color: red;
   margin-top: 0;
   }
  -->
</style>
</head>
<body style="margin: 0">
<?php
$fields_1 =	array("fusername" => "User Name", "fpassword" => "Password");
$fields_2 = array("user_name" => "User Name", "password" => "Password", "email" => "Email", "first_name" => "First Name", "last_name"	=> "Last Name", "street" => "Street", "city" => "City", "state" => "State", "zip" => "Zip", "phone" => "Phone", "fax" => "Fax" );
?>
<div id="wrapper">
  <div id="login">
   <form action=<?php echo $_SERVER['PHP_SELF']?>
method="POST">
      <fieldset style='border: 2px solid #000000'>
        <legent>Login Form</legent>
<?php
if (isset($message_1))
{
  echo "<p class='errors'>$message_1</p>\n";
}
foreach($fields_1 as $field => $value)
{
  if(preg_match("/pass/i",$field))
    $type = "text";
  else
    $type = "text";
  echo "<div id='field'>
    <label for='$field'>$value</label>
    <input id='$field' name='$field' type='$type'
    value='".@$$field."' size='20' maxlength='50' />
    </div>\n";
}
?>
<input type="submit" name="Button"
       stype='margin-left: 45%; margin-bottom: .5em'
      </fieldset>
    </form>
    <p style='text-align: center; margin: 1em'>
If you already have an account, log in.</p>
    <p style='text-align: center; margin: 1em'>
If you do not have an account, register now.</p>
  </div>
  <div id="reg">
    <form action=<?php echo $_SERVER['PHP_SELF']?>
  method="POST">
      <fieldset style='border: 2px solid #000000'>
       <legend>Registration Form</legend>
<?php
if(isset($message_2))
{
  echo "<[ class='errors'>$message_2</p>\n";
}
foreach($fields_2 as $field => $value)
{
  if($field == "state")
  {
    echo "<div id='field'>
      <label for='$field'>$value</label>
      <select name='state' id='state'>";
      $stateName=getStateName();
      $stateCode=getStateCode();
      for ($n=1;$n<=50;$n++)
      {
	$state=$stateName[$n];
	$scode=$stateCode[$n];
	echo "<option value='$scode'";
	if ($scode== "AL")
	    echo " selected";
	echo ">$state</option>\n";
      }
      echo"</select></div>";
  }
  else
  {
    if(preg_match("/pass/i",$field))
      $type = "password";
    else
      $type = "text";
    echo "<div id='field'>
      <label for=$field'>$value</label>
      <input id=$field' name='$field' type='$type'
      value='".@$$field."' size='40' maxlength='65' />
      </div>\n";
   } //end else
} // end foreach field
?>
<input type="submit" name="Button"
    style='margin-left: 45%; margin-bottom: .5em'
    value="Register">
      </fieldset>
    </form>
  </div>
</div>
</body></html>

 

I think you are missing something which i marked comment

Index.php:

<?php

<?php
if (isset($message_1))
{
  echo "<p class='errors'>$message_1</p>\n";
}
foreach($fields_1 as $field => $value)
{
  if(preg_match("/pass/i",$field))
    $type = "text";                       //It should be {$type = "text";}
  else
    $type = "text";                       //It should be {$type = "text";}
  echo "<div id='field'>
    <label for='$field'>$value</label>
    <input id='$field' name='$field' type='$type'
    value='".@$$field."' size='20' maxlength='50' />
    </div>\n";
}
?>
<input type="submit" name="Button"
       stype='margin-left: 45%; margin-bottom: .5em'
      </fieldset>
    </form>
    <p style='text-align: center; margin: 1em'>
If you already have an account, log in.</p>
    <p style='text-align: center; margin: 1em'>
If you do not have an account, register now.</p>
  </div>
  <div id="reg">
    <form action=<?php echo $_SERVER['PHP_SELF']?>
  method="POST">
      <fieldset style='border: 2px solid #000000'>
       <legend>Registration Form</legend>
<?php
if(isset($message_2))
{
  echo "<[ class='errors'>$message_2</p>\n";
}
foreach($fields_2 as $field => $value)
{
  if($field == "state")
  {
    echo "<div id='field'>
      <label for='$field'>$value</label>
      <select name='state' id='state'>";
      $stateName=getStateName();
      $stateCode=getStateCode();
      for ($n=1;$n<=50;$n++)
      {
	$state=$stateName[$n];
	$scode=$stateCode[$n];
	echo "<option value='$scode'";
	if ($scode== "AL")
	    echo " selected";
	echo ">$state</option>\n";
      }
      echo"</select></div>";
  }
  else
  {
    if(preg_match("/pass/i",$field))
      $type = "password";                 // It should be {$type = "password";}
    else
      $type = "text";                        // It should be {$type = "text";}
    echo "<div id='field'>
      <label for=$field'>$value</label>
      <input id=$field' name='$field' type='$type'
      value='".@$$field."' size='40' maxlength='65' />
      </div>\n";
   } //end else
} // end foreach field
?>
<input type="submit" name="Button"
    style='margin-left: 45%; margin-bottom: .5em'
    value="Register">
      </fieldset>
    </form>
  </div>
</div>
</body></html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.