Jump to content

script not working...


xyn

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.