Jump to content

Why doesn't this function work?


kryoxis

Recommended Posts

All the tables are correct and it's making the connect to the database fine it's just not working, did I write it wrong?

 

 

function newPm($to, $from, $title, $text){
$q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC");
$lastMsg = $db->fetch_assoc($q);
$mid = $lastMsg['mt_id'] + 1;
$msgId = $lastMsg['mt_msg_id'] + 1;
$db->query("INSERT INTO ibf_message_topics SET mt_id=$mid, mt_msg_id=$msgId, mt_date=". time(). ", mt_title='$title', mt_from_id=$from, mt_to_id=". $to. ", mt_vid_folder='in', mt_read=0, mt_owner_id=$to, mt_user_read=0") or die(mysql_error());
$db->query("INSERT INTO ibf_message_text SET msg_id=$msgId, msg_date=". time() .", msg_post='$text', msg_sent_to_count=1, msg_author_id=$from") or die(mysql_error());
$userq = $db->query("SELECT new_msg FROM ibf_members WHERE id = $to");
$userData = $db->fetch_assoc($userq);
$msgCount = $userData['new_msg'] + 1;
$db->query("UPDATE ibf_members SET new_msg=$msgCount, show_popup=1 WHERE id = $to") or die(mysql_error());
}

 

 

Here's how that function is being called in the beginning of the page:

 

 

if($action =="banUser"){
$expire = time() + (3600000 * 24 * $_GET['duration']);
$q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC");
$lastMsg = $db->fetch_assoc($q);
$mid = $lastMsg['mt_id'] + 1;
$msgId = $lastMsg['mt_msg_id'] + 1;
$title = "Notification";
$duration = $_GET['duration'] ." days";
if($_GET['duration'] == "1"){
	$duration = "1 day";
}
if($_GET['duration'] == "Forever"){
	$duration = "forever";
}
$temp = 0;
if($expire > time()){
	$temp = 1;
}
$body = "This automated message has been sent to notify you that your account has been banned $duration.  To appeal this ban, click on Irc from the menu on the homepage and ask to speak to a moderator.  If this ban is temporary, your account will be reinstated automatically at the appropriate time";
newPm($id, 3017, $title, $body);
$msgCount = $_GET['msg'] + 1;
$db->query("UPDATE ibf_members SET ban_level = $level, tempbanned = $temp, banned = 1, ban_expire='$expire', ban_reason='". $_GET['reason']."', ban_by='". $name."' WHERE id=$id") or die(mysql_error());
?>
<center><b>User banned!</b> (<a href="index.php?code=plyrmgmt">Back to Player Management</a>)</center>

Link to comment
Share on other sites

You have a bunch of code, and a lot of different things that could be problems. 

 

For example, you have a function .... is it a function or a method in a class?  In that function you refer to a $db variable, which looks like a database class, but there is no instantiantion with new, and that variable is not a parameter or a global variable, so that would be a problem.  Is that really your code?

 

The biggest problem however, is that you didn't actually say, specifically, what doesn't work.  "It's just not working" is not a sufficient explanation.

Link to comment
Share on other sites

It's not doing what the "querys" are telling it to do.. (sending the message) Would you like me to post my whole page? It's kinda big..

the $db is fine it's just connecting to the database previously mentioned at the top of the page (not posted on here though) Shouldn't make any difference I don't believe.. I came here looking for help because I'm not that experienced.

Link to comment
Share on other sites

It's not doing what the "querys" are telling it to do.. (sending the message) Would you like me to post my whole page? It's kinda big..

the $db is fine it's just connecting to the database previously mentioned at the top of the page (not posted on here though) Shouldn't make any difference I don't believe.. I came here looking for help because I'm not that experienced.

 

Of course it makes a difference.  Inside a function you can't just use a variable that you didn't pass as a parameter or declare global.  Objects that contain resources (database or file handles) are even more sensitive.

Link to comment
Share on other sites

Hmm... Well it's weird because the function that's right below it seems to work perfectly, heres the code for it

 

function getName($id){
$other = $db->fetch_assoc($db->query("SELECT name FROM ibf_members WHERE id = ". $id));
$otherName = $other['name'];
if(preg_match("[a-zA-Z0-9_]", $otherName)){
	$otherName.=" (valid)";
}
return $otherName;
}

 

any idea?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.