Jump to content

[SOLVED] Check for registered email


Dada78

Recommended Posts

I have a login form and it works great but I need to add a script to it that will check for a registered email when you login and if you try to login with an email that isn't registered then it will show an error like "That isn't a registered email, try again".

 

Here is the code for my login

 

<?php

session_start();

include ('db_connect.php');

if(isset($_POST['submit']))
    {
    if(empty($_POST['email']))
        $error = 'Please fill in email field.';
    elseif(empty($_POST['password']))
        $error = 'Please fill in desired password field.';
    else
        {    
     
      // email and password sent from signup form
      $email=$_POST['email'];
      $password=$_POST['password'];
     
      $sql="SELECT * FROM users WHERE email='$email' and password='" . md5($password) . "'"; 
      $result=mysql_query($sql);
     
      // Mysql_num_row is counting table row
      $count=mysql_num_rows($result);
      // If result matched $email and $password, table row must be 1 row

      if($count==1)
      {
         // Register $email, $password and redirect to file "user.php"
         $_SESSION['hasLoggedIn'] = 1;

      //get the users id that is associated with him
       $SQL2 = "SELECT * FROM users WHERE email='$email'";
       $result2 = mysql_query($SQL);
       $row = mysql_fetch_assoc($result);

   //store the id in the session for use
       $_SESSION['userID'] = $row['id'];
      
         session_register("email");
         header("location:user.php");
      }
   }
}

?>

 

 

If anyone can help me with this that would be great.

 

-Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/88343-solved-check-for-registered-email/
Share on other sites

I tried the above suggestions and I am getting this error.

 

Parse error: syntax error, unexpected T_ELSE in /home/mesquit1/public_html/local/login.php on line 44

 

Here is the code, did I put it in the wrong place or do something else wrong?

 

<?php

session_start();

include ('db_connect.php');

if(isset($_POST['submit']))
    {
    if(empty($_POST['email']))
        $error = 'Please fill in email field.';
    elseif(empty($_POST['password']))
        $error = 'Please fill in desired password field.';
    else
        {

      // email and password sent from signup form
      $email=$_POST['email'];
      $password=$_POST['password'];

      $sql="SELECT * FROM users WHERE email='$email' and password='" . md5($password) . "'";
      $result=mysql_query($sql);

      // Mysql_num_row is counting table row
      $count=mysql_num_rows($result);
      // If result matched $email and $password, table row must be 1 row

      if($count==1) {

         // Register $email, $password and redirect to file "user.php"
         $_SESSION['hasLoggedIn'] = 1;

      //get the users id that is associated with him
       $SQL2 = "SELECT * FROM users WHERE email='$email'";
       $result2 = mysql_query($SQL);
       $row = mysql_fetch_assoc($result);

   //store the id in the session for use
       $_SESSION['userID'] = $row['id'];

         session_register("email");
         header("location:user.php");
      }

        } else {

       $error = 'Wrong email or password, try again.';

      }
    }
  }

?>

 

-Thanks

 

 

You've got an extra curly bracket before your else

 

Try

 

      if($count==1) {

         // Register $email, $password and redirect to file "user.php"
         $_SESSION['hasLoggedIn'] = 1;

      //get the users id that is associated with him
       $SQL2 = "SELECT * FROM users WHERE email='$email'";
       $result2 = mysql_query($SQL);
       $row = mysql_fetch_assoc($result);

   //store the id in the session for use
       $_SESSION['userID'] = $row['id'];

         session_register("email");
         header("location:user.php");
      } else {

       $error = 'Wrong email or password, try again.';

      }

Ok I am getting this error now and I have played with it for a bit and can't get it to go away. Usally that means I haven't closed a bracket or have an extra one but they seemed to all be closed.

 

Parse error: syntax error, unexpected $end in /home/mesquit1/public_html/local/login.php on line 194

 

Here is the entire file. What am I missing or doing wrong?

 

<?php

session_start();

include ('db_connect.php');

if(isset($_POST['submit']))
    {
    if(empty($_POST['email']))
        $error = 'Please fill in email field.';
    elseif(empty($_POST['password']))
        $error = 'Please fill in desired password field.';
    else
        {

      // email and password sent from signup form
      $email=$_POST['email'];
      $password=$_POST['password'];

      $sql="SELECT * FROM users WHERE email='$email' and password='" . md5($password) . "'";
      $result=mysql_query($sql);

      // Mysql_num_row is counting table row
      $count=mysql_num_rows($result);
      // If result matched $email and $password, table row must be 1 row

      if($count==1) {

         // Register $email, $password and redirect to file "user.php"
         $_SESSION['hasLoggedIn'] = 1;

      //get the users id that is associated with him
       $SQL2 = "SELECT * FROM users WHERE email='$email'";
       $result2 = mysql_query($SQL);
       $row = mysql_fetch_assoc($result);

   //store the id in the session for use
       $_SESSION['userID'] = $row['id'];

         session_register("email");
         header("location:user.php");
      } else {

       $error = 'Wrong email or password, try again.';

      }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Mesquite Texas Country Christmas" />
<meta name="keywords" content="Mesquite, Texas, Country Christmas" />
<meta name="author" content="NA" />
<link rel="stylesheet" type="text/css" href="/stylesheet.css" media="screen" title="FBC" />
<script type="text/javascript" src="drop_down.js"></script>
<title>A Mesquite Country Christmas - Login</title>
</head>
<body>

<div id="wrap">

<a href="/index.html">
<img id="frontphoto" src="/images/header.png" width="760" height="237" alt="Mesquite Country Christmas" border="0"></a>

<div id="menu">

<h2 class="hide">Menu:</h2>

<ul id="avmenu">
<li><a href="/index.html">Home</a></li>
<li><a href="/christmasstory.html">The Christmas Story</a></li>
<li><a href="/directions.html">Directions</a></li>
<li><a href="#">Information</a><ul>
      <li><a href="/information.html">Display Facts & Info</a></li>
      <li><a href="/faq.html">FAQ</a></li>
      <li><a href="/playlist.html">2008 Playlist</a></li>
      <li><a href="#">Christmas History</a></li>
  </ul></li>
<li><a href="#">Photos</a>
  <ul>
      <li><a href="/2007photos.html">2007</a></li>
  </ul></li>
<li><a href="#">Videos</a>
  <ul>
      <li><a href="/2007videos.html">2007</a></li>
  </ul></li>
<li><a href="/guestbook.php">Guestbook</a></li>
<li><a href="/webcam.html">Web Cam</a></li>
<li><a href="/webradio.html">Internet Radio</a></li>
<li><a href="http://www.noradsanta.org/" TARGET="_blank">Track Santa</a></li>
<li><a href="/projects.html">Projects & How Tos</a></li>
<li><a href="/links.html">Links</a></li>
<li><a href="/contact_us.html">Contact Us</a></li>
</ul>

<center><a href="http://www.toysfortots.org/" TARGET="_blank"><img src="/images/toys_for_tots.jpg" border="0" width="110" height="153" vspace="10"></a></center>

<center><a href="http://christmas.bronners.com/2007/house/534.html"><img src="http://christmas.bronners.com/voteforme/vote.jpg" border="0" width="110" height="153" alt="christmas decorations" vspace="10"></a></center>

</div>

<div id="content">


<div class="fadebox">

<h2>Login Now</h2>

<hr />

	<p>Log into your account to submit new displays as well as modify existing ones. Registration is free, so if you don't already have an account, <a href="/local/register.php">create one</a>!</p>

	<table width="28%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>	
	<table width="300" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong> User Login</strong></td>
</tr>
<tr>
<td width="78"> Email:</td>
<td width="294"><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td> Password:</td>
<td><input name="password" type="password" id="password" size="30"></td>
</tr>
<tr>
<td colspan="2" align="right" class="errorText">
<?PHP
// then we check for the error message
if (isset($error)) {
   echo $error . '<br />';
}
?> </td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</td>
</tr>
<tr>
<td><table width="300" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td>
<p><a href="/local/forgot.php">Forgot Password</a> | <a href="/local/register.php">Register</a></p>
</td>
</tr>
</table></td>
</tr>
</table>


</div>



   </div>
</div>

<div id="footer">
© 2007 Mesquite Country Christmas

<br />
<br />

<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//468x60, created 1/8/08
google_ad_slot = "0360766123";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


</div>

</div>
</body>
</html>

 

-Thanks

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.