Warning: preg_replace_callback(): Requires argument 2, '$func['entity_fix']('\2')', to be a valid callback in /nfs/c01/h06/mnt/10927/domains/dragonprime.net/html/Sources/Load.php(225) : runtime-created function on line 3
A spot of sql help?
DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • September 21, 2019, 11:02:14 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1] 2   Go Down
  Print  
Author Topic: A spot of sql help?  (Read 9016 times)
0 Members and 1 Guest are viewing this topic.
Edward
Mod God
*****
Offline Offline

Posts: 592

Now... Who's a Llama?


View Profile
« on: June 30, 2009, 07:59:19 PM »

For some odd reason, this refuses to work, where it should.  Undecided. Yes, this is 097. Any idea anyone?
Code:
<?
require_once "common.php";
isnewday(2);
if ($_GET[op]=="mute"){
page_header("Muted");
addnav("Superuser Grotto","superuser.php");
$user = $HTTP_GET_VARS['user'];
$sql = "UPDATE accounts SET muted=1 WHERE acctid='$user'";
  db_query($sql);
  output("This player has been muted.");
}
if ($_GET[op]=="mute2"){
page_header("Advance muted");
addnav("Superuser Grotto","superuser.php");
$user = $HTTP_GET_VARS['user'];
$sql = "UPDATE accounts SET muted=2 WHERE login=$user";
  db_query($sql);
  output("This player has been advance muted.");
}
if ($_GET[op]=="unmute"){
page_header("Unmuted");
addnav("Superuser Grotto","superuser.php");
$user = $HTTP_GET_VARS['user'];
$sql = "UPDATE accounts SET muted=0 WHERE login=$user";
  db_query($sql);
  output("This player has been unmuted.");
}
page_footer();
?>

EDIT:
There is no error or anything, it just does not set.
« Last Edit: June 30, 2009, 08:22:00 PM by Edward » Logged
Boris735
Mod God
*****
Offline Offline

Posts: 570


View Profile
« Reply #1 on: June 30, 2009, 08:13:32 PM »

It would help if you indicated more about the failure mode, what you tried, what you expected, and what happened instead.  Saying something like "When I try to mute a user, the muted field does not get updated, but then I try to advance mute them it does" (or reverse) is much more helpful than "this refuses to work".

That said, I can see two potential issues; I'm not familiar enough with 0.9.7 to say for sure which, if either, is the cause.

Firstly, the SQL statements are using "UPDATE accounts [...]" directly, whereas in v1.1+ this should be "UPDATE " . db_prefix("accounts") . " [...]".  I don't know if the prefix was introduced for v1, but it's a good habit to get into if it was also present in v0.97.

More relevantly, though, your SQL queries are using the user field to identify the row(s) in question to modify.  All well and good, but this is being done in three different ways, and I'd lay odds on at most one of them being correct.

That is, you're using "[...] WHERE acctid = $user", "[...] WHERE login = $user", and "WHERE lastip = $user".  That last one in particular is highly suspicious.  I don't know whether $user is supposed to match the account ID or the login, but I'd imagine these all need to be changed to the same thing.
Logged
MarcTheSlayer
Mod God
*****
Offline Offline

Posts: 1752


View Profile
« Reply #2 on: July 01, 2009, 03:12:11 AM »

$_GET[op] doesn't have any quotes. Although this wont cause any major problems, it makes good sense to add them. Smiley

$HTTP_GET_VARS['user'] - What are you passing here, a number or a name?

Maybe you should change $_GET to $HTTP_GET_VARS (or vice versa) and see if that makes any different?
Logged

Check My Modules for the latest versions.
robert
Old Dog
Mod God
*****
Offline Offline

Posts: 1047


LoGD Buff!


View Profile WWW
« Reply #3 on: July 01, 2009, 10:17:30 AM »

I am no pro using MYSQL, so I try to make it as easy for me as possible.
Quite often, I end up rewriting the statements or code several times before getting it right.

You used a variable in the sql.
I found it easier for me to include the variable into an output statement as well,
doing so, verifies for me the info I want to be set into the db.

IE:
output("This player has been muted.");
I would write this as:
output("Player $user has been muted.");

Another way for you to accomplish the same result would be to add 'muted' into the user.php
  - then just edit the player as you normally would

P.S.
You dont need the (db prefix) in 097 code, that was introduced in v1.x
Logged

MarcTheSlayer
Mod God
*****
Offline Offline

Posts: 1752


View Profile
« Reply #4 on: July 01, 2009, 10:33:10 AM »

IE:
output("This player has been muted.");
I would write this as:
output("Player $user has been muted.");

This is the preferred/correct method in v1.0.0+ as it allows for translations. Smiley
Code:
output("Player %s has been muted.", $user);

I don't know if this is also the case in previous versions.

« Last Edit: July 01, 2009, 10:35:19 AM by Afkamm » Logged

Check My Modules for the latest versions.
White Knight
Mod God
*****
Offline Offline

Posts: 1030

For the truth!


View Profile
« Reply #5 on: July 02, 2009, 03:05:10 AM »

IE:
output("This player has been muted.");
I would write this as:
output("Player $user has been muted.");

This is the preferred/correct method in v1.0.0+ as it allows for translations. Smiley
Code:
output("Player %s has been muted.", $user);

I don't know if this is also the case in previous versions.

Translations work differently in the GPL'd versions. I don't remember output being passed to a formatting function back then.

@Edward:
You are most likely using PHP 5 and/or your host disabled the deprecated globals. Use $_GET instead of $HTTP_GET_VARS.
Logged

Helping you help yourself.
Edward
Mod God
*****
Offline Offline

Posts: 592

Now... Who's a Llama?


View Profile
« Reply #6 on: July 02, 2009, 12:22:30 PM »

Sorry, I have been gone for the past day, unable to get on and respond.

Sorry for the confusion, I was putting things as this and that and they didnt exactly have the logical information...
This would be the "correct" bit of code which should mute a player,
Code:
if($HTTP_GET_VARS['op']=="mute"){
$char = $HTTP_GET_VARS['char'];
$sql = "UPDATE accounts SET muted=1 WHERE login='$char'";
db_query($sql);
output("$char has been muted.");
}
And this bit in the bio.php file, which leads to the bit above,
Code:
if($row['muted']==0){
addnav("Mute user","tools.php?op=mute&char=".$row['login']);
For some odd reason, the sql does not stick, it is executed, but does not change the table at all - I have checked the spelling of everything, compared it with the table, and it still does not work. This topic also seems to have the same problem as I am, with the sql not sticking and changing the table.

$_GET[op] doesn't have any quotes. Although this wont cause any major problems, it makes good sense to add them. Smiley
$HTTP_GET_VARS['user'] - What are you passing here, a number or a name?
Maybe you should change $_GET to $HTTP_GET_VARS (or vice versa) and see if that makes any different?
Thank you, I have added them(as above). The second bit wasnt the logical part, the one in this post is though. ':-). Playing around with it, $_GET and $HTTP_GET_VARS seem to have the same effect.

I am no pro using MYSQL, so I try to make it as easy for me as possible.
Quite often, I end up rewriting the statements or code several times before getting it right.
You used a variable in the sql.
I found it easier for me to include the variable into an output statement as well,
doing so, verifies for me the info I want to be set into the db.
IE:
output("This player has been muted.");
I would write this as:
output("Player $user has been muted.");
Another way for you to accomplish the same result would be to add 'muted' into the user.php
  - then just edit the player as you normally would
P.S.
You dont need the (db prefix) in 097 code, that was introduced in v1.x
Added that bit too - thank you :-). Aye, I just did add it in to user.php - it seems to 'stick' right, not reverting back to 0/unmuted.

IE:
output("This player has been muted.");
I would write this as:
output("Player $user has been muted.");
This is the preferred/correct method in v1.0.0+ as it allows for translations. Smiley
Code:
output("Player %s has been muted.", $user);
I don't know if this is also the case in previous versions.
That seems not to work,  :-P. I don't think the translator in an unedited version of 097 actually works, I just added a link to the translator in the grotto of an unedited version, and it tosses up a few errors, such as an undefined variable, undefined index, and an undefined function... LoL.
@Edward:
You are most likely using PHP 5 and/or your host disabled the deprecated globals. Use $_GET instead of $HTTP_GET_VARS.
Both $_GET and $HTTP_GET_VARS have the same effect,  Lips Sealed.

Meh, its alright, I will use the user.php way. Sql seems not to work in the file eitherway - updating the table, with either muted, gold, gems, anything - so I guess I should use the other way.
Thank you, all.  :-)
Logged
White Knight
Mod God
*****
Offline Offline

Posts: 1030

For the truth!


View Profile
« Reply #7 on: July 02, 2009, 12:55:16 PM »

Run the following two queries, one at a time. See what they tell you.
SELECT @@GLOBAL.sql_mode
SELECT @@SESSION.sql_mode
Logged

Helping you help yourself.
Edward
Mod God
*****
Offline Offline

Posts: 592

Now... Who's a Llama?


View Profile
« Reply #8 on: July 02, 2009, 05:08:52 PM »

No text was displayed, so I guess something is wrong. For SELECT @@GLOBAL.sql_mode, here is a screenshot of what was displayed when ran in the database... and here is SELECT @@SESSION.sql_mode. I think something is wrong.  Undecided
« Last Edit: July 02, 2009, 05:37:43 PM by Edward » Logged
MarcTheSlayer
Mod God
*****
Offline Offline

Posts: 1752


View Profile
« Reply #9 on: July 02, 2009, 05:23:21 PM »

@@SESSION working link image

On the left where it lists your tables, quite a few are missing. I doubt the game will work without them, but it does so they must be somewhere, so why aren't they listed? :-/
Logged

Check My Modules for the latest versions.
Edward
Mod God
*****
Offline Offline

Posts: 592

Now... Who's a Llama?


View Profile
« Reply #10 on: July 02, 2009, 05:42:34 PM »

@@SESSION working link image

On the left where it lists your tables, quite a few are missing. I doubt the game will work without them, but it does so they must be somewhere, so why aren't they listed? :-/

Sorry about that, ':-D. Edited the post do it was right.
There are tables missing? Clan, moderatedcomments, gamelog, ext... none of that existed in 097, :-P. It is different in a few ways. =).

Logged
White Knight
Mod God
*****
Offline Offline

Posts: 1030

For the truth!


View Profile
« Reply #11 on: July 02, 2009, 05:46:34 PM »

No, there are no missing tables that I can tell. I think my installation used to have 1 less (when I had that installation). Anyway, the results are good. Empty for both of them means no weird mode is set, and certainly strict mode isn't set. Which means that your code should work. Have you tried to run the same update statement from phpmyadmin?
Logged

Helping you help yourself.
White Knight
Mod God
*****
Offline Offline

Posts: 1030

For the truth!


View Profile
« Reply #12 on: July 02, 2009, 05:53:47 PM »

Sorry for the double-post, but... it just occurred to me that I don't remember "muted" being a valid field in accounts. You inserted it into the database before trying to update it, right?
Logged

Helping you help yourself.
Edward
Mod God
*****
Offline Offline

Posts: 592

Now... Who's a Llama?


View Profile
« Reply #13 on: July 02, 2009, 06:08:24 PM »

No, there are no missing tables that I can tell. I think my installation used to have 1 less (when I had that installation). Anyway, the results are good. Empty for both of them means no weird mode is set, and certainly strict mode isn't set. Which means that your code should work. Have you tried to run the same update statement from phpmyadmin?
Yup, I added a table, the marriage table(um, no relation to the bed!!). Smiley.
Oh wonderful, thank you. Yeah, it works when ran directly in phpmyadmin.

Sorry for the double-post, but... it just occurred to me that I don't remember "muted" being a valid field in accounts. You inserted it into the database before trying to update it, right?
Nope, muted is not a 'starting' field in accounts. Yup, I did add it in before trying to update it.
Logged
White Knight
Mod God
*****
Offline Offline

Posts: 1030

For the truth!


View Profile
« Reply #14 on: July 02, 2009, 06:25:43 PM »

Try doing a SELECT login,muted FROM accounts immediately after and see if the query takes. I see no reason for it not to as you say that everything works outside of PHP. The only thing left to check after that would be to see if code that executes after this resets the value. Because it seems to me that everything else is working as it should. If all else fails, create a separate table with account id/login/mute information and use that instead of accounts.
Logged

Helping you help yourself.
Pages: [1] 2   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
21 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search