0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by israrkhan
0

You can just put login.php in your homepage. In the user validation maybe will be look like this :

<?php
session_start();
mysql_connect("localhost","root","");
mysql_select_db("abc");
$username=$_POST["username"];
$password=md5($_POST["password"]);
$cek="select * from login
where username=’$username’ and password=’$password’";
$jalankan=mysql_query($cek);

if (mysql_num_rows($jalankan)){
$_SESSION["member"]=$username;
header("Location:welcomepage.php");
}
else{
echo "Failoed to login!";
}
?>

I hope that will help you.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

-1

u should go to php myadmin then create your own database and the creat a table which will keep the username and password fields.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.