Jump to content

Recommended Posts

Hey,
I have a PM system and wanted to alert any user if they receive a new PM whilst somewhere else on the site. I attached my code into the sessions which is on every page it doesn't work.

I had a new Pm and it wouldn't alert me:
[code=php:0]include "db.php";
$ssql = mysql_query("SELECT * FROM pm WHERE sendto='{$_SESSION['user']['user']}' AND stats='0'");
$numb = @mysql_num_rows($ssql);
if( $numb > 0 )
{
echo '<script>alert("You have got a new Private message")</script>';
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/14793-script-not-working/
Share on other sites

You could try something like...
$query = "SELECT COUNT(*) FROM pm WHERE sendto='{$_SESSION['user']['user']}' AND stats='0'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
    echo '<script>alert("You have got a new Private message")</script>';
}

Question: Why do you have $_SESSION['user']['user']? Why don't you use use $_SESSION['user']?

And, some people disable javascript so your alert wouldn't do anything anyways.

You can put <noscript> tags around an alternate message for people who turn it off. That way, they would be notified even if they have javascript turned off.
Link to comment
https://forums.phpfreaks.com/topic/14793-script-not-working/#findComment-59077
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.