okay i've created my database called hcprintc_mm , i have a table called user with 3 fields: id (primary key & auto increment), username, and password.
I then inserted the values mm36203 as the user name and sch2010 as the password.
I have an index.html with the following:
<!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">
<head>
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" type="text/css" href="style.css" title="style" media="screen" />
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
$(".block").fadeIn(1000);
$(".idea").fadeIn(1000);
$('.idea').supersleight();
$('#username').example('Username');
$('#password').example('Password');
});
/* ]]> */
</script>
</head>
<body>
<div id="wrap">
<div class="idea">
<p>Mellow Mushroom - Schedule Login</p>
</div>
<div class="block">
<form action="checkLogin.php" method="post" name="form1">
<div class="left"></div>
<div class="right">
<div class="div-row">
<input type="text" id="myusername" name="myusername" onfocus="this.value='';" onblur="if (this.value=='') {this.value='Username';}" value="Username" />
</div>
<div class="div-row">
<input type="password" id="mypassword" name="mypassword" onfocus="this.value='';" onblur="if (this.value=='') {this.value='************';}" value="************" />
</div>
<div class="rm-row">
<input type="checkbox" value="c" name="rm" id="remember"/> <label for="remember">Remember me?</label>
</div>
<div class="send-row">
<button id="login" value="login" type="submit" name="login"></button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
Then I have a checkLogin.php file:
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="hcprintc_mm"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:loginSuccess.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
Then I have a loginSuccess.php file:
<?php
session_start();
if(!session_is_registered(myusername)) {
header("loacation:index.html");
}
?>
<!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=utf-8" />
<title></title>
</head>
<body>
<h1>Login Successful!</h1>
<a href="logout">Log Out!</a>
</body>
</html>
This is the error I am getting when i try to login on the website: "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mm36203'@'localhost' (using password: YES) in /home3/hcprintc/public_html/mm/checkLogin.php on line 10
cannot connect"
am I supposed to give php the direct path (like in the error) to my database?

New Topic/Question
Reply



MultiQuote




|