Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking userid and email match 1

Status
Not open for further replies.

benluke4

Technical User
Jan 27, 2005
127
GB
Hi,

Ive built an admin area for a site im working on. Ive set up a form where the customer services fill in the userid and email of a that user. My problem is that im trying to make the php script check that the userid and email configure against what is already stored in the database. I just dont know how to do it.
This is what i have so far
MY FORM
Code:
<form action="register.php" method="post" onsubmit="return check(this)">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">

    <tr> 
      <td nowrap> <p class="formtext">First Name: <font color="#FF0000">*</font> 
          <br>
          <input name="first_name" type="text" class="FormField" size=36>
          &nbsp;&nbsp;</td>
      <td valign="top"> <p class="formtext">Last Name: <font color="#FF0000">*</font> 
          <br>
          <input name="last_name" type="text" class="FormField" size=36>
      </td>
    </tr>
    <tr> 
      <td height="46"> 
        <p class="formtext">Email:<font color="#FF0000">*</font> 
          <br>
          <input name="email_address" type="text" class="FormField" size=36>
      </td>
      <td nowrap>
  <p class="formtext">Unique User ID Number<font color="#FF0000">*</font> <br>
          <input name="userid" type="text" class="FormField" size=6>
      </td>
    </tr>
    <tr align="left"> 
      <td colspan="2"> <input type="submit" name="add" value="Submit"></td>
    </tr>
  </table>
</form>

REGISTRATION.PHP
Code:
<?php 
include '../db.php';

/* grabs the POST variables and puts them into variables that we can use */ 
$first_name= $_POST['first_name'];
$last_name= $_POST['last_name']; 
$email_address= $_POST['email_address']; 
$user_name= $_POST['email_address'];
$userid= $_POST['userid'];  

/* Let's strip some slashes in case the user entered
any escaped characters. */

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name );
$email_address = stripslashes($email_address);
$user_name = stripslashes($user_name);
$userid = stripslashes($userid);

/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email_address) || (!$userid)){
	echo 'You did not submit the following required information! <br />';
	if(!$first_name){
		echo "First Name is a required field. Please enter it below.<br />";
	}
	if(!$last_name){
		echo "Last Name is a required field. Please enter it below.<br />";
	}
	if(!$email_address){
		echo "Email Address is a required field. Please enter it below.<br />";
	}
	if(!$userid){
		echo "Email Address is a required field. Please enter it below.<br />";
	}
	include 'index.html'; // Show the form again!
	/* End the error checking and if everything is ok, we'll move on to
	 creating the user account */
	exit(); // if the error checking has failed, we'll exit the script!
}

I want to then check that the inputed email address matches the email address that currently exists in the datbase for the given user id

If it does the script will carry on, if it doesn't ill echo something.

Thanks for any help

Ben
 
Code:
$db = mysql_connect('localhost','root','pwd');
  $sql = "select email from users where userId='$userId'";
  $rs = mysql_query($sql);
  $row = mysql_fetch_row($rs);
  if (mysql_num_rows($rs)){
    if ($row[0] == $email_address){
      print "Authenticated";
    } else {
      print "Email address doesn't match";
    }
  } else {
    return "Userid doesn't exist";
  }

Obviously, I am assuming you have the database set up already so just modify the field names.
 
Thanks tweenerez, thats works just right

Thanks

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top