Pop up alert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
batowiise
Forum Commoner
Posts: 28
Joined: Fri Dec 17, 2010 7:11 am

Pop up alert

Post by batowiise »

Hi all,

I need the PHP code for the following scenario and this is the logic:

If user_session = username
and financealert == 'yes'
pop up an alert.

Your help is much needed.

Regards.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pop up alert

Post by social_experiment »

What does you code currently look like? It doesn't help all that much if the code is fed to you like binary soup because you won't understand how it works and what the premise behind it is :|
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
batowiise
Forum Commoner
Posts: 28
Joined: Fri Dec 17, 2010 7:11 am

Re: Pop up alert

Post by batowiise »

The following is my code:

<?php
session_start();
$_SESSION['$username'];

require_once("admin/db.php");
$result = mysql_query("SELECT financealert, username FROM users WHERE financealert='yes'") or die(mysql_error());
if($user_session == $username && $financealert == 'yes') {
?>
<script type="text/javascript">
windows.alert('ATTENTION');
</script>
<?php
}
?>

The alert is not showing anyway.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pop up alert

Post by social_experiment »

The problem seems to lie in the logic of the script

Code: Select all

<?php if($user_session == $username && $financealert == 'yes') ?>
Nowhere in the script is any of the variables ($user_session, $username, $financealert) defined, so your script executes but when it comes to the decision making it has nothing to check against and the alert is not displayed.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
batowiise
Forum Commoner
Posts: 28
Joined: Fri Dec 17, 2010 7:11 am

Re: Pop up alert

Post by batowiise »

Hi all,

I have got this code and it does not really look at the database, it just pops up with the alert when i log onto the system. Can anyone help me out and tell me what i am not doing right?

<?php
session_start();
$username = $_SESSION['username'];

require_once("admin/db.php");
$result = mysql_query("SELECT financealert FROM users WHERE financealert='Yes'") or die(mysql_error());
$sendAlert = mysql_result($result,0,'financealert');

if($_SESSION['username'] == $username && $sendAlert == 'Yes')
{
echo"<script>alert('gh');</script>";
}
?>

Need your help.

Regards.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pop up alert

Post by social_experiment »

Code: Select all

<?php $_SESSION['username'] == $username && $sendAlert == 'Yes' ?>
It looks like both conditions are met so the script continues and displays the popup?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
batowiise
Forum Commoner
Posts: 28
Joined: Fri Dec 17, 2010 7:11 am

Re: Pop up alert

Post by batowiise »

Hi,

I wanted the pop up to appear only when the user that is logged in has been assigned 'yes' on the financealert field. The issue now is that the pop up keeps coming up even if the 'yes' has not been assign to that particular user.

Regards.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pop up alert

Post by social_experiment »

Code: Select all

<?php $result = mysql_query("SELECT financealert FROM users WHERE financealert='Yes'") or die(mysql_error()); ?>
It will continue to pop up because you are selecting financealert and it's value is 'Yes'. What is the purpose of this query because you are selecting a value based on it's own value which seems rather redundant to me.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply