Forum Moderators: coopster

Message Too Old, No Replies

Login Script Issues

         

paseo

7:29 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



For whatever reason, the below code which is a common script is not working for me. Whenever a login is attempted or a new user attempts to registerm, the var_query_error is returned. The database is being logged into 100% at the very top of the page. This below is the register functio. When the call to INSERT into $table the query errors out.?

function register($cusid,$userpass,$remember) {
$cusid = mysql_escape_string($cusid);
$userpass = mysql_escape_string(md5($userpass));

$result=mysql_fetch_array(mysql_query("SELECT * FROM $table WHERE cusid = '{$cusid}'"), MYSQL_ASSOC);
if (!$result) { //insert record if user name doesn't exist
$insert = mysql_query("INSERT INTO $table VALUES ('', '$cusid', '$userpass', '', '', '')") or DIE ($this->query_error);
$result = mysql_fetch_array(mysql_query("SELECT * FROM $table WHERE cusid = '{$cusid}' AND userpass = '{$userpass}'"), MYSQL_ASSOC) or DIE ($this->query_error);
$this->message .= '<p>Registration was successful</p>';
$this->set_session($result,$remember,true); //log user on
return true;
} else {
$this->message .= '<p>username already exists! Please choose a different name</p>';
return false;
}
}

whoisgregg

8:19 pm on Jan 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first thing I would do is echo your SQL statements and run them manually to see if there is an error building the statements.

$sql = "INSERT INTO $table VALUES ('', '$cusid', '$userpass', '', '', '')";
echo $sql; // for debugging
$insert = mysql_query($sql) or DIE ($this->query_error);

paseo

8:19 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



Will do

paseo

8:28 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



This is the result

INSERT INTO mapp VALUES ('', '11', '(32-bit md5 hash here)', '', '', '')ERROR: something went wrong when accessing the database. Please consult your webmaster

the 11 is the $cusid and the long number is the $userpass after md5

[edited by: coopster at 12:04 pm (utc) on July 6, 2007]
[edit reason] removed specifics [/edit]

paseo

8:46 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



Its almost as if its not connecting to the DB. Is there a way to check db connectivity?

eelixduppy

8:49 pm on Jan 29, 2007 (gmt 0)



mysql_error [us2.php.net] will give you the last error encountered by mysql. If you aren't properly connected to the database, it will let you know.

paseo

9:02 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



How exactly would i set this up. I cant seem the get the syntax correct..;)

paseo

9:07 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



I get - 1044: Access denied for user 'username'@'%' to database 'aaa'

I get - 0: when using the correct db name

[edited by: coopster at 12:05 pm (utc) on July 6, 2007]

eelixduppy

9:27 pm on Jan 29, 2007 (gmt 0)



Well there is a couple reasons why this may not allow you to connect.
1) You don't have the correct username/password/location/permissions. Make sure that your host allows
localhost
. For example, Yahoo hosting uses
mysql

2) You have to reset your password to use the old authentication protocol [dev.mysql.com].

Of course there may be other reasons. These seem to be the most common.

Good luck :)