we have just started learning PHP as a course in our 2nd year subject Internet Application development. below are the codes that we have worked on so far.
Homepage :
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor='yellow'>
<P align='center'><FONT color='blue' size='6'>ABC & Company</FONT></P>
</BODY>
</HTML>
Login.php :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#99FF00" >
<form action="validateUserLogin.php" method="post">
User Name <input type="text" name="textBox1" /> <br>
Password <input type="password" name="txtPassword" /> <br>
<input type="submit" value="Ok" />
<input type="button" value="Cancel" />
</form>
</body>
</html>
User Login Validation:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFF00">
<p><font color="#FF0000" size="+2">Validating the user login...</font></p>
<!-- Access the incoming username, password values -->
<!--access the incoming data -->
<?php
$s1 = $_POST['textBox1'];
$s2 = $_POST['txtPassword'];
//echo $s1;
//echo '<BR>';
//echo $s2;
?>
<!-- check/compare those values with the database values -->
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';
// make foo the current db
$db_selected = mysql_select_db('abc', $link);
if (!$db_selected) {
die ('Can\'t use abc : ' . mysql_error());
}
$query = "SELECT UserName, Password FROM t_user WHERE UserName='$s1' AND Password='$s2'";
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
/*
if (!$result) {
echo 'Invllied user login details';
$message = 'Invalid query: ' . mysql_error() . "\n";
} else {
echo 'Successfull login, welcome to the Sales site';
}*/
echo '<BR>';
if ($row = mysql_fetch_assoc($result)) {
//echo $row['UserName'];
echo '<BR>';
echo 'Successfull login, welcome to the Sales site';
//echo $row['Password'];
} else {
echo '<BR>';
echo 'Invllied user login details';
}
mysql_close($link);
?>
<!-- if valied username, password then show the welcome page -->
<!-- if not(invalied) show error message -->
</body>
</html>
Welcome Page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFF00">
<marquee><P><font color="#FF0000" size="2">Welcome to ABC</font></P></marquee>
<P align="center"><font color="#0000FF" size="+2"><B> Main Page </B></font></P>
</body>
</html>
please let me know how i connect all these. i just have the code but dont know how to connect to mySQL, how do you compare user logins with a database etc. i need urgent help.
Thanks so much