I have the following PHP code... (sensitive data switched with +++)
<?php
$host="triplestrata.com"; // Host name
$username="+++"; // Mysql username
$password="+++"; // Mysql password
$db_name="+++"; // Database name
$tbl_name="++_+++"; // Table name
// Connect to server and select databse.
mysql_connect("triplestrata.com", "+++", "+++")or die("cannot connect");
mysql_select_db("+++")or die("cannot select DB");
// username and password sent from form
$user_login=$_POST['user_login'];
$user_pass=$_POST['user_pass'];
// To protect MySQL injection (more detail about MySQL injection)
$user_login= stripslashes($user_login);
$user_pass= stripslashes($user_pass);
$user_login= mysql_real_escape_string($user_login);
$user_pass= mysql_real_escape_string($user_pass);
$sql="SELECT * FROM $tbl_name WHERE username='$user_login' and password='$user_pass'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $user_login and $user_pass, table row must be 1 row
if($count==1){
// Register $user_login, $user_pass and redirect to file "login_success.php"
session_register("user_login ");
session_register("user_pass");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
I know this sounds like a pretty basic question but where do I input my Db data? I've tried placing it in the beginning but it doesn't work. I get a connection error.
Then there's how I should put it, when placing the username and Db name, should I include or ignore the prefix? IE a Db named 'mybase' and the username 'user1':
would it be
$host="localhost"; // Host name
$username="user1"; // Mysql username
$password="password"; // Mysql password
$db_name="mybase"; // Database name
$tbl_name="members"; // Table name
?
I get this error:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'cpanel.123.45.67.89.webhost.com' (using password: YES) in /home/user/public_html/checklogin.php on line 11 cannot connect
But I changed everything to match the Db tables... Ideas? Thanks