Having problems making this work, please help:
****************************************************
Login.php:
<?php
session_start();
require_once('dbcon.php');
try
{
$db = getConnection();
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
$sql=("SELECT name, password FROM subscriber WHERE name='$username' and password='$password'");
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
echo "$count" . "$username" . " " . "$password";
if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success.php'>";
header("location:login_success.php");
}
//else {
//echo "Wrong Username or Password";
//}
}
catch( PDOException $e ) {
echo $e->getMessage();
}
?>
****************************************************
dbcon.php:
<?php
//connect to the database
function getConnection(){
$username = 'xxxxxxxxxx';
$password = 'xxxxxxxxx';
$dbname = 'xxxxxxxxxx';
$db = new PDO( "mysql:host=localhost;dbname=$dbname", $username, $password );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $db;
}
?>
****************************************************
Error i'm getting: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061)
Please please help!
****************************************************
Login.php:
<?php
session_start();
require_once('dbcon.php');
try
{
$db = getConnection();
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
$sql=("SELECT name, password FROM subscriber WHERE name='$username' and password='$password'");
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
echo "$count" . "$username" . " " . "$password";
if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success.php'>";
header("location:login_success.php");
}
//else {
//echo "Wrong Username or Password";
//}
}
catch( PDOException $e ) {
echo $e->getMessage();
}
?>
****************************************************
dbcon.php:
<?php
//connect to the database
function getConnection(){
$username = 'xxxxxxxxxx';
$password = 'xxxxxxxxx';
$dbname = 'xxxxxxxxxx';
$db = new PDO( "mysql:host=localhost;dbname=$dbname", $username, $password );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $db;
}
?>
****************************************************
Error i'm getting: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061)
Please please help!