DB connect...

Soldato
Joined
26 Nov 2005
Posts
3,839
Location
Doon the Bay (Newcastle)
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!
 
slight change:

<?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);
$result = $db->$query

// 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();
}
?>

seems like its having problems with that in bold
 
dbcon.php

<?php
//connect to the database
function getConnection(){
$username = 'xxx';
$password = 'xxx';
$dbname = 'xxx';
$db = new PDO( "mysql:host=localhost;dbname=$dbname", $username, $password );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
return $db;
}

?>

so $result = $db->$query($sql); instead of $result = $db->$query;

$_SESSION array ("username"); instead of session_register("username");

Sorry but which brackets to get rid of?
 
Thanks for your help bud i got it sorted.

Combo of things you put up there and bit of trial and error
 
Back
Top Bottom