PDA

View Full Version : Changing field names


xLive_Gaming
07-19-2007, 11:54 PM
OK, I have jsut downlaoded a Instant Messenger script which I will hopefully integrate in to my site but I have ran in to a few problems, could anyone possiblely help:

So far I have the made it so the registration works and it adds to the right table which is the users.

Orginal Code:

case 'login':
///////////// login to the server /////////
// login parts (within array $_POST): //
// from - user logging in //
// pwd - password //
///////////////////////////////////////////
$query = @mysql_query("SELECT buddylist FROM ".SQL_PREFIX."users WHERE username='".mysql_real_escape_string($from)."' AND password='".$pwd."'");
if(@mysql_num_rows($query) > 0) {
$user = mysql_fetch_assoc($query);
$set_status = @mysql_query("UPDATE ".SQL_PREFIX."users SET is_online='1' WHERE username='".mysql_real_escape_string($from)."'");
if(strlen($user['buddylist']) > 0) {
$buddylist = user_event($from, $user['buddylist'], 'status,1');
$output['buddy'] = $json->encode($buddylist);
} else {
$output['buddy'] = Array();
}

print($json->encode($output));
} else {
print 'invalid';
}
break;

An here is my atempt at changing username and password to alias and pass.

I have added all the correct fields to my table.

case 'login':
///////////// login to the server /////////
// login parts (within array $_POST): //
// from - user logging in //
// pwd - password //
///////////////////////////////////////////
$query = @mysql_query("SELECT buddylist FROM users WHERE alias='".mysql_real_escape_string($from)."' AND pass='".$pwd."'");
if(@mysql_num_rows($query) > 0) {
$user = mysql_fetch_assoc($query);
$set_status = @mysql_query("UPDATE users SET is_online='1' WHERE alias='".mysql_real_escape_string($from)."'");
if(strlen($user['buddylist']) > 0) {
$buddylist = user_event($from, $user['buddylist'], 'status,1');
$output['buddy'] = $json->encode($buddylist);
} else {
$output['buddy'] = Array();
}

print($json->encode($output));
} else {
print 'invalid';
}
break;

Can anyone notice anyhting that make it not work?

Thanks
xLG

guelphdad
07-20-2007, 12:06 AM
if you didn't change the names of the actual columns in the table then your new query won't work.

xLive_Gaming
07-20-2007, 12:11 AM
What i'm trying to do is i'm trying to make it work with a current system we have isntalled, i have put all the fields in to the table, but instead of using username and password the system I am using has alias and pass, therefore i'm trying to change the code so that it will check the detials aginst alias and pass not username and password if you get me?

Fumigator
07-20-2007, 04:06 AM
Step one would be adding error checking:


$result = mysql_query($query);
if (!$result) {
die("SQL Error! query text: $query<br />Error text: ".mysql_error());
}

bigbobby
07-20-2007, 01:17 PM
no message is appearing any where :s