visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: problems with admin login mySql db


By: PHP newbee U.S.A.  Date: 06/12/2002 00:00:00  English  Points: 100 Status: Answered
Quality : Excellent
Hello,
I am trying to create a login page for my admin site, which starts a session, If the admin name and pass are in db (logged in), they get a main menu buttun and a session is started. If not in db they get a try again link. Whats happeneing is that the page is coming up blank, no errors, just blank.

So I have a couple of requests, first can someone point out my error, also, can someone tell me how to enable my errors so I can see them, show errors is turned on IE.



<html><head></head><body>
<?
// do_html_URL() function
function do_html_URL($url, $name)
{ // begin
?>
<a href="<?=$url?>"><?=$name?></a>

<?
} // end do_html_URL
?>


<?
function login($username, $password)

{ // begin login function
// this function checks the username and password with the db table for admin users
// connect to db
// check if username is unique
$db_name = "xxxxxxxxxxxx";

$table = "admin";

//1

$connection = @mysql_connect("xxxxxxx", "xxxxxxxx", "xxxxxxxxxx") or die("Problems connecting - Try again");

//2

$result = mysql_query("SELECT adminID, adminName, adminPass FROM '$table' WHERE adminName='$username' AND adminPass ='$password'");

if(!$result)

do_html_url("login.php", " Wrong Login Infromation try again");


if(mysql_num_rows($result) > 0)

do_html_url("MenuView.php", " Welcome to the Adminsitration Site");
session_register('valid');
$valid = "yes";

else

do_html_url("login.php", " Wrong Login Infromation try again");


} // end login() function
?>
</body></html>
By: TheFalklands Date: 06/12/2002 02:50:00 English  Type : Comment
check this out...


if(!$result)
do_html_url("login.php", " Wrong Login Infromation try again");

if(mysql_num_rows($result) > 0){ // CHECK HERE
do_html_url("MenuView.php", " Welcome to the Adminsitration Site");
session_register('valid');
$valid = "yes";
}else // AND HERE
do_html_url("login.php", " Wrong Login Infromation try again");



cheers =0)
By: PHP newbee Date: 06/12/2002 05:03:00 English  Type : Comment
no i tried that allready,

tx though

By: digitaltree Date: 06/12/2002 06:56:00 English  Type : Comment
Don't put $table in quotes in your SQL statement.

$result = mysql_query("SELECT adminID, adminName, adminPass FROM '$table' WHERE adminName='$username' AND adminPass ='$password'");

should be

$result = mysql_query("SELECT adminID, adminName, adminPass FROM $table WHERE adminName='$username' AND adminPass ='$password'");

As for your errors, put the following line after any mysql_query that you want to see the errors for:

echo mysql_error();
By: PHP newbee Date: 06/12/2002 08:18:00 English  Type : Comment
I changed the code to this, but now I'm the error 3 message. My query is making my wonder

this part
adminPass=password('password')


<html><head></head><body>
<?
// do_html_URL() function
function do_html_URL($url, $name)
{ // begin
?>
<a href="<?=$url?>"><?=$name?></a>

<?
} // end do_html_URL
?>

<?
function login($username, $password)

{ // begin login function
// this function checks the username and password with the db table for admin users
// connect to db
// check if username is unique
$db_name = "xxxxxxxxxx";

$table = "admin";

//1

$connection = @mysql_connect("xxxxxxxxxxx", "xxxxxxxxx", "xxxxxxxxxxxx") or die("Problems connecting - Try again");

//2

$sql = "SELECT adminID, adminName, adminPass FROM $table WHERE adminUser = '$username' AND adminPass = password('$password')";

$result = @mysql_query($sql, $connection) or die("Error3 - Couldn't connect - try again later");

if(mysql_num_rows($result) > 0){

do_html_url("MenuView.php", " Welcome to the Adminsitration Site");
session_register('valid');
$valid = "yes";

} else

do_html_url("login.php", " Wrong Login Infromation try again");



} // end login() function
?>
<?
error_reporting (E_ALL ^ E_NOTICE);
?>
<?
login($HTTP_POST_VARS['username'],$HTTP_POST_VARS['password']);
?>

</body></html>
By: digitaltree Date: 06/12/2002 09:19:00 English  Type : Comment
your query should look like:

$sql = "SELECT * FROM $table WHERE adminUser = '$username' AND adminPass = '$password'";

or:

$sql = "SELECT * FROM $table WHERE adminUser = '" . $username . "' AND adminPass = '" . $password . "'";

try'em... both work

=0)
By: PHP newbee Date: 06/12/2002 10:50:00 English  Type : Comment
no it didnt work
By: PHP newbee Date: 06/12/2002 10:51:00 English  Type : Comment
getting this error

Error3 - Couldn't connect - try again later"
By: TheFalklands Date: 06/12/2002 15:57:00 English  Type : Comment
That sounds more like a mysql connection limit or something, not a problem in the code.
By: PHP newbee Date: 06/12/2002 16:52:00 English  Type : Comment
whats an sql connection limit, and how do i fix it
By: VGR Date: 07/12/2002 07:14:00 English  Type : Comment
it means an invalid host/databasename/password towards mySqld

I can show you a different solution using HTTP BASIC Authentication
By: PHP newbee Date: 07/12/2002 07:25:00 English  Type : Comment
that would be great
By: TheFalklands Date: 08/12/2002 21:09:00 English  Type : Comment
Something fishy about mysqld only.

Some mysqld related :
1. check open connections using "mysqladmin version"
2. check max_connections and socket used by mysqld : using "mysqladmin variables"
3. check existence of socket "/tmp/mysql.sock" or "/var/lib/mysql/mysql.sock" and mysqld running

4. U can increase max_connections of mysqld "/etc/my.cnf"
[mysqld]
.
.
set-variable = max_connections=300
.
.

5. You can "cat /var/lib/mysql/`hostname`.err" for knowing the reason of mysqld connection failure


By: VGR Date: 08/12/2002 21:23:00 English  Type : Comment
here it is
you may use in stead standard HTTP Authentication via META-TAGS :

(in PHP) :


function authenticate() {
Header( "WWW-authenticate: basic realm='My Authentication System'");
Header( "HTTP/1.0 401 Unauthorized");
echo "You must enter a valid login ID and password to access this resource\n";
exit;
}

if(!isset($PHP_AUTH_USER)) { // || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER)) ) {
authenticate();
}
else while (($PHP_AUTH_PW!="hardcoded_password1")and($PHP_AUTH_PW!="hardcoded_password2")) authenticate(); // no need of a DB (althought it ouwld be better)


regards
By: PHP newbee Date: 08/12/2002 21:38:00 English  Type : Comment
thanks VGR,
actually I am allready using a similar method now for my login, now that i think about it, their will only be 2 users, so I can continue with this system
By: VGR Date: 08/12/2002 22:21:00 English  Type : Answer
yes, why not ?

(I also use it for one , two, three users or ***categories*** of users (like "users and admins")

If you need a DB to store logins and password, I have some code, too.

Do register to be able to answer

EContact
browser fav
page generated in 383.803840 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page