I'm a newcomer to PHP and am trying to do a login/session for a user. I keep getting errors. Any Help would be greatly appreciated. 

```
   <?php session_start();     
  include('./config.php');
  $email=$_POST['email'];
  $email=htmlspecialchars($email);
  $Password=$_POST['password'];
  $Password=htmlspecialchars($Password);
  $ip=$_SERVER['REMOTE_ADDR'];
  $result = mysql_query("SELECT * FROM member WHERE email='$email' AND password='$Password'") or trigger_error(mysql_error());
  $count = mysql_num_rows($result);
  while($row = mysql_fetch_array($result)){
$logfirstname=$row['firstname'];
$loglastname=$row['lastname'];
$logid=$row['id'];
$logemail=$row['email'];
$logphone=$row['phone'];
$logbiz=$row['biz_id'];
$logdate=$row['date_joined'];
$logaddress=$row['address'];
$logsponsored=$row['sponsored'];
  }
 if ($count>0){
$_SESSION['auth']=1;
$_SESSION['id']=$logid;
$_SESSION['biz']=$logbiz;
$_SESSION['name']=$logfirstname." ".$loglastname;
$sess=$logfirstname." ".$loglastname;
if ($logsponsored === "1") { $_SESSION['sponsored']=1;}
mysql_query($result);
mysql_close();
session_regenerate_id();
$sid=session_id();

 include('./config.php');   
$loginr=mysql_query("INSERT INTO login (sessionid, memberid, username, IPAddr,    LogInTime, Status, name)
VALUES ('$sid', '$logid', '$email', '$ip', NOW(), 'On', '$sess')");
mysql_query($loginr);
mysql_close();

  header("Location: controlpanel.php");
   exit();
  }else{
  header('Location: login.php?fail=1');
  exit();
  }

 ?>`

```