Jump to content

Login Database Validation


yddib

Recommended Posts

This is the code for my login page form. It has Javascript form validation to ensure the fields are not blank. BUT if the fields are filled in they then get onto the site but with no profile (like a social network) How do I do an if statement to bring them to another "You are not a member" page!

 

 

<html>
<head>

<meta content="text/html; charset=UTF-8" />
<title>UCC: Alumni, Donors and Friends</title>
<link rel="stylesheet" href="4en.css" type="text/css" />

<link rel="stylesheet" href="43en.css" type="text/css" />

<script language="javascript">

function open_win() 
{
window.open("forgot-password.html")
}

var username;
var password;
var x;
function validate1()
{
x=document.myForm;
username=x.email.value;
password=x.pass.value;


if (username =="")
{
alert("Please fill in the Email Address field");
x.email.focus();
return false;
}

else if (password =="")
{
alert("Please fill in the Password field");
x.pass.focus();
return false;
}


else
{
return true;
}
}

</script>


</head>
<body>

<form name="myForm" method="POST" action="login.php" onSubmit="return validate1();"> 
<font face="Arial" style="font-size: 11pt">Email Address:<font> <INPUT TYPE="text" SIZE="20" name="email"><BR> 
<font face="Arial"><span style="font-size: 11pt">Password:</span>  </font><INPUT TYPE="password" SIZE="20" name="pass"><br/><br/>



<input type="submit" value="Submit" name="B1" style="font-family: Arial; font-weight: bold"> 
<input type="reset" value="Reset" name="B2" style="font-family: Arial; font-weight: bold"> 
<br /><a onclick="open_win()" </><font size="2"color="#990000"><u>Forgot Your Password?</u></a></font></p>
</form> 
</p>
<br />
    <p align="center"><font face="Arial" style="font-size: 11pt">Not a member?</font></p>

     <font face="Arial">
     <a href ="form.html">
     <p align="center"><font size="5" color="#990000"> Register Now!</font></a></p>

</td>
   </tr>
 </table>
 </center>
</body>
</html>

 

login.php code:

 

<?php
session_start();

$email =  ADDSLASHES($_POST['email']); 
$pass = ADDSLASHES($_POST['pass']);

mysql_connect("", "", "") or die(mysql_error());
//connects to the blacknight server
mysql_select_db("db1002023_4grads");
//selects the database called 4grads

$resultc = @mysql_query("SELECT u_id FROM gradinfo where email ='$email' and pass ='$pass' ");
if (!$resultc) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

$rowc = mysql_fetch_array($resultc);

$_SESSION['id'] = $rowc['u_id'];


?>

<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="description goes here" />
<meta name="keywords" content="keywords,goes,here" />
<link rel="stylesheet" href="style1.css" type="text/css" />
<!--[if IE 6]>
<link rel="stylesheet" href="fix.css" type="text/css" />
<![endif]-->
<script type="text/javascript">

function open_win() 
{
window.open("/board")
}

</script>
<script type="text/javascript">

function open_win() 
{
window.open("/board")
}

function popup(){
var answer = confirm ("Are you sure you want to log out?")
if (answer)
window.location="logout.php"
}
</script>
</head>


<body>

<div id="sidebar">
<img src="translogo.jpg" alt="Logo" /><br /><br /><br /><br />
<div id="menu" style="width: 170; height: 220">
<a class="active" href="profile.php">Profile </a>
<a href="contacts.php">Contacts </a> 
<a href="edu.php">Education </a> 
<a href="career.php">Career </a> 
<a href="photos.php">Photos </a> 
<a href="comments.php">Comments </a> 
<a href="college.php">College</a>
</div>

</div>

<div id="content">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" background="bannercreator-nu2.gif" height="55">
 <tr>
   <td width="20%" height="55" align="center">
   <a onclick="open_win()" /><font color="#FFFFFF" size="2">Message Board</font></a></td>
   <td width="20%" height="55" align="center">
   <td width="20%" height="55" align="center"> </td>
<td width="20%" height="55" align="center"> </td>
   <td width="10%" height="55" align="center">
   <a href="help1.php"><font color="#FFFFFF" size="2">Help</font></a></td>
   <td width="10%" height="55" align="center">
   <a onClick="popup()"><font color="#FFFFFF" size="2">Log Out</font></a></td>
 </tr>
</table>


<hr>
<?php 
$id = $_SESSION['id'];

mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("database");

$resultb = @mysql_query("SELECT f_name, l_name FROM gradinfo where u_id='$id' ");
if (!$resultb) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($rowb = mysql_fetch_array($resultb)) {
echo "<h1 style='text-align: left'>".$rowb['f_name']." ".$rowb['l_name']."</h1><br />";

}
?>
<p>

<?php 


mysql_connect("host", "user", "password") or die(mysql_error());
//connects to the blacknight server
mysql_select_db("db");

print("<font size='2' face='Arial'>
	<table style='BORDER-COLLAPSE: collapse' width='500' border='0' cellspacing='5'>
	<tr>"); 


$resulta = @mysql_query("SELECT pic FROM gradinfo where u_id='$id' ");
if (!$resulta) {
exit('Error performing query: ' . mysql_error());
}

while ($rowa = mysql_fetch_array($resulta)) {
echo "<td width='30%' align='center' valign='top'><p align='center'><img src='".$rowa['pic']."' alt='No profile picture uploaded'/></p></td>";

}


print("<td width='70%' bgColor='#fafafa' cellpadding='2'><font size='2'>"); 

$result = @mysql_query("SELECT birthd, birthm, birthy, location, gender, relationship, about_me FROM gradinfo where u_id='$id' ");
if (!$result) {
exit('Error performing query: ' . mysql_error());
}

while ($row = mysql_fetch_array($result)) {

echo '<b>Gender</b>: '.$row['gender'].'<br/><br/><b>Date of Birth</b>: ' .$row['birthd'] . '|' .$row['birthm'] .'|' .$row['birthy'] .  '<br/><br/><b>Location:</b> ' .$row['location'] . '<br/><br/><b>Relationship status:</b> '.$row['relationship'].'</font><br/><br/><br/><a href="update12.php"><font size="2">Edit profile</font></a></td></tr>';

echo "<tr> <td width='100%' colspan='2' align='left' bgColor='#fafafa' cellpadding='2'><font size='2'><b>About me:</b><br/>".$row['about_me']."</td></tr></table>";
}


?> 
<br/><br/>

<a>Education</a>
<?php

mysql_connect("mysql71.cp.blacknight.com", "u1002023_llal", "ebusiness") or die(mysql_error());
//connects to the blacknight server
mysql_select_db("db1002023_4grads");
//selects the database called 4grads

$result = @mysql_query("SELECT u_course, u_year FROM gradcoll where u_id ='$id'");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_array($result);
echo "<table width='500' bgcolor='#fafafa'><tr><td>";
echo "<font size='2.5'><b>Course:</b> ".$row['u_course']. "</font><br/><br/>";
echo "</td></tr><tr><td>";
echo "<font size='2.5'><b>Year:</b> ".$row['u_year']. "</font>";
echo "</td></tr></table>";

?>
<br/><br/>
<a>Career</a>
<?php

mysql_connect("host", "user", "pass") or die(mysql_error());

mysql_select_db("db");

$result = @mysql_query("SELECT occupation, company FROM gradwork where u_id ='$id'");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
$row = mysql_fetch_array($result);
echo "<table width='500' bgcolor='#fafafa'><tr><td>";
echo "<font size='2.5'><b>Occupation:</b> ".$row['occupation']. "</font><br/><br/>";
echo "</td></tr><tr><td>";
echo "<font size='2.5'><b>Company:</b> ".$row['company']."</font>";
echo "</td></tr></table>";
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/124298-login-database-validation/
Share on other sites

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.