...

View Full Version : Problems with my syntax



axd
03-29-2009, 03:11 PM
Hello, kinda new to PHP and MYSQL, I have created a website through using tutorials. It works well but i need to edit a small section of code to allow for editing users, and am not sure of the correct mysql syntax (or php, tbh i am not sure which category this falls under, so if it should be in php I apologise in advance). On with the issue....



I have this code....


/**
* procDeleteInactive - All inactive users are deleted from
* the database, not including administrators. Inactivity
* is defined by the number of days specified that have
* gone by that the user has not logged in.
*/
function procDeleteInactive(){
global $session, $database;
$inact_time = $session->time - $_POST['inactdays']*24*60*60;
$q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
."AND userlevel != ".ADMIN_LEVEL;
$database->query($q);
header("Location: ".$session->referrer);



I am trying to add another user level to be ignored when deleting inactive users. The user level is called PREMIUM_LEVEL, but i am unsure of the correct way to add it after the


$q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
."AND userlevel != ".ADMIN_LEVEL;

I have the PREMIUM_LEVEL etc all set up, i just need advice on adding it to the end of this statement, so it ignores both ADMIN_LEVEL and PREMIUM_LEVEL


Many thanks to all who reply

Dan

Old Pedant
03-29-2009, 09:44 PM
Just tack it on:


$q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
." AND userlevel != ".ADMIN_LEVEL
." AND userlevel != ".PREMIUM_LEVEL;

Or you could get a tiny bit more sophisticated:


$q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
." AND userlevel NOT IN (" . ADMIN_LEVEL . "," . PREMIUM_LEVEL . ")";

I have to ask: What format are you using for $inact_time???

Since you don't have apostrophes around that value, it needs to be in the form YYYYMMDDhhmmss *as a number*. Is that what you have? (The hhmmss is optional.)

Don't forget to leave a space before the keyword AND! I almost missed that.

Hey...I'm NOT a PHP person. How come you don't need the dollar sign in front of ADMIN_LEVEL and PREMIUM_LEVEL????

axd
03-29-2009, 10:19 PM
Hi and thanks for the swift reply.

Theres a couple of lines just above that that i didnt paste in, i think i just pasted the end to show you what i needed.

I am not too sure on code myself, but i think heres where it states how long "inactive" is by the 24*60*60 multiplied by the amount of days selected from the main admin page from a drop down menu, and then deleted respectivley



function procDeleteInactive(){
global $session, $database;
$inact_time = $session->time - $_POST['inactdays']*24*60*60;
$q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
."AND userlevel != ".ADMIN_LEVEL;
$database->query($q);
header("Location: ".$session->referrer);


I think the ADMIN_LEVEL is a function defined earlier in the php, maybe why there is no $dollar sign there

Old Pedant
03-30-2009, 04:18 AM
Well, it would be a good idea to DEBUG.

echo or print your $q value to the screen, to see exactly what the actual query given to the DB is going to be.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum