SQL database problem

Zstream

Diamond Member
Oct 24, 2005
3,395
277
136
Here is my code to connect

############### Code

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="orderofb_test"; // Database name
$tbl_name="orderofb_test.members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>


This is the error message I receive.

############### Code

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/orderofb/public_html/php/checklogin.php on line 11
cannot connect


I changed all the permissons to 777 and I still receive this error.

$tbl_name="orderofb_test.members"; // Table name

Is this the correct table name? Here is a pic of my phpmyadmin

Picture
 

KLin

Lifer
Feb 29, 2000
30,193
553
126
Try excluding orderofb_test from the table name variable. members is the actual table name.
 

clamum

Lifer
Feb 13, 2003
26,252
403
126
I agree with George, might want to double-check your credentials just in case.

Also, I've got MySQL/PHP 4 for my web hosting and for SQL queries I didn't need to specify the database name before the table name. Just a thought in case you get an error after you resolve the database connection issue.
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
I dont think it has anything to do with tablename, because it says it is failing at mysql_connect() so the table name is of no consequence at that point. But still like KLin said, when you do resolve the connection problem you dont need to specify the schema name ("orderofb_test") since you are calling select_db on it. You would only need to specify that if you wanted to connect to a table other than the schema you have currently selected.

but as for your connection issue- like George says- you sure your username password are correct? Echo those variables out before you connect so you can confirm that they are being passed in correctly. Also, is the database running on your local machine? I notice it says localhost so just wanted to make sure...

finally I also noticed your login method is vulnerable to SQL injection hacking. just something to keep in mind in case this is for anything that might be exposed to public. using a prepared statement with placeholders for username/password would be the way to evoid that.
 

Zstream

Diamond Member
Oct 24, 2005
3,395
277
136
Here is the html page code that I use to insert the userid. The useird is john and the password is supposed to be 1234

The database shows the userid and password in the row so I am confused. :(

I did change the table back and forth, I tried numerous times with no result. Now, one thing I did notice is that I do not have a database configuration file. I thought this was setup when you created the DB? Am I wrong on that?

config.php or Settings.php ?


<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
for the username, try orderofb_john

most shared hosting accounts will prefix all databases and mysql usernames with the account name
 

Zstream

Diamond Member
Oct 24, 2005
3,395
277
136
Originally posted by: troytime
for the username, try orderofb_john

most shared hosting accounts will prefix all databases and mysql usernames with the account name

No luck :*(
 

clamum

Lifer
Feb 13, 2003
26,252
403
126
Originally posted by: troytime
for the username, try orderofb_john

most shared hosting accounts will prefix all databases and mysql usernames with the account name
Oh yeah that's true, same here. So no luck prefixing the username with your web account name? Hmmm...
 

exdeath

Lifer
Jan 29, 2004
13,679
10
81
The first question is, has it ever worked before?

Try logging into mySQL console manually with the same credentials (nobody/NO?). What is the proper credential for anonymous users and is anon access enabled? Then try with something else like a random email address and no password, and if that works, the problem is with PHP's choice of anonymous log on credentials, etc.

Just a suggestion for future progress, encapsulate errors in exceptions so you can extract useful data from the error object and format your own error message.

As you can see, a PHP function is failing inside and your "cannot connect" error handler is being bypassed and you get nastiness puked up on the users browser.

Looking at your last post I'm confused, are you trying to log in as john/1234 or anonymously as shown in your first post? I assume you are logging into the database anonymously and then searching for your app specific logon data john/1234?