Page 1 of 1
Pop up alert
Posted: Mon Dec 20, 2010 2:35 am
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.
Re: Pop up alert
Posted: Mon Dec 20, 2010 3:05 am
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

Re: Pop up alert
Posted: Mon Dec 20, 2010 4:55 am
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.
Re: Pop up alert
Posted: Mon Dec 20, 2010 6:05 am
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.
Re: Pop up alert
Posted: Tue Dec 21, 2010 6:37 am
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.
Re: Pop up alert
Posted: Tue Dec 21, 2010 7:04 am
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?
Re: Pop up alert
Posted: Tue Dec 21, 2010 10:29 am
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.
Re: Pop up alert
Posted: Tue Dec 21, 2010 10:50 pm
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.