Possible Duplicate:
PHP - MySQL access denied error - Works in other programs
i'm trying to make a login process that connect between my AdminLogin2.php and admin2 table inside my phpmyadmin, but it said access denied. i've no idea what should i do to fix it..Hope someone can help me here. here my code, Thank You.
`<?php
$host="localhost";
$username="root";
$password="";
$database="finalproject";
$table="admin2";
$AdminID=$_POST['Field1'];
$Password=$_POST['Field3'];
mysql_connect("$host","$password") or die (mysql_error());
#echo"connected";
mysql_select_db("$database") or die (mysql_error());
#echo"database found";
// To protect MySQL injection (more detail about MySQL injection)
$AdminID = stripslashes($AdminID);
$Password = stripslashes($Password);
$AdminID = mysql_real_escape_string($AdminID);
$Password = mysql_real_escape_string($Password);
$sql="SELECT * FROM $admin2 WHERE username='$AdminID' and password='$Password'";
$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:AdminForm.php");
}
else {
echo "Wrong Username or Password";
}
?>
`
mysql_*
functions as they are in the deprecation process. Use MySQLi or PDO instead.