views:

44

answers:

2

I'm trying to get the user's login details from the database using $SETTINGS["admin_username"] and also the password. I have defined them as 'user' (for username) and pass (for password), and I want them to be pulled from database table userLogin.

Any ideas? Please help, I have tried everything but the page either doesn't open or it doesn't work at all.

<?php
error_reporting(0);
$SETTINGS["admin_username"]='user';
$SETTINGS["admin_password"]='pass';
$SETTINGS["mysql_user"]='user';
$SETTINGS["mysql_pass"]='pass';
$SETTINGS["hostname"]='localhost';
$SETTINGS["mysql_database"]='db_db';

$connection = mysql_connect($SETTINGS["hostname"], $SETTINGS["mysql_user"], $SETTINGS["mysql_pass"]) or die ('request "Unable to connect to MySQL server."'.mysql_error());

$db = mysql_select_db($SETTINGS["mysql_databas… $connection) or die ('request "Unable to select database."');
?>
A: 

I can't read your code, so I try to write it again, here:

<?php

error_reporting(0);

$SETTINGS["admin_username"]='user';

$SETTINGS["admin_password"]='pass';

$SETTINGS["mysql_user"]='user';

$SETTINGS["mysql_pass"]='pass';

$SETTINGS["hostname"]='localhost';

$SETTINGS["mysql_database"]='db_db';

$connection = mysql_connect($SETTINGS["hostname"], $SETTINGS["mysql_user"], $SETTINGS["mysql_pass"]) or die ('request "Unable to connect to MySQL server."'.mysql_error());

$db = mysql_select_db($SETTINGS["mysql_database", $connection) or die ('request "Unable to select database."');

$sql = "SELECT * FROM userLogin LIMIT 1";
$rs = mysql_query($sql, $connection) or die(__LINE__.":".mysql_error());
while(false !== ($r = mysql_fetch_assoc($rs)))
{
    $SETTINGS["admin_username"]=$r['field_user'];
    $SETTINGS["admin_password"]=$r['field_pass'];
}

?>

Notice this line:

$sql = "SELECT * FROM userLogin LIMIT 1";

I use this in assumption that you only have 1 entry on table userLogin. If it's not, maybe you can use the following alternative query (because I don't know your current table's schema):

$sql = "SELECT * FROM userLogin WHERE field_user = 'admin'";
silent
Damit... I wasnt very clear...
Buki
THANK YOU!!! Yep i finally got it!!!!
Buki
good! and welcome to stackoverflow
silent
A: 

For starters, you've got an error in your syntax, Line 12 (and so does silent in his reproduction):

$db = mysql_select_db($SETTINGS["mysql_databas… $connection) or die ('request "Unable to select database."');

I'm guessing you want

$db = mysql_select_db($SETTINGS["mysql_database"], $connection) or die ('request "Unable to select database."');
willell
Thanks guys!!! Stackflow RULES!!!
Buki