View Full Version : Code Not Working Properly

02-02-2007, 03:11 AM
Hey All,

I am making a script that allows a DJ on a radio site, per say, to send a user a message by their ip. What it does is it when the dj uses the alert ip form it enters 3 details into a db; the dj who sent it(fromdj), the message for the user (message), and the ip address for it to be sent to (toip).

So I use a script that says if the users ip is the same as the one in the db then display the message that corresponds. Except, the message is always displayed even if the users ip doesn't match and I can't figure out why! The code I use is below - any help would be great!

$ipaddr = $_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT id, toip, message, fromdj FROM rp_alerts ORDER BY id ASC") or die(mysql_error());
$row = mysql_fetch_array($result);
if($ipaddr = $row['toip']) {
echo '<script language="JavaScript" type="text/javascript">
alert("DJ '.$row['fromdj'].' Says: '.$row['message'].'")</script>';
$result = mysql_query("DELETE FROM rp_alerts WHERE id = '$row[id]'") or die(mysql_error());

And fyi - the second part deletes the message once it has been displayed to the user.

Any help is great! Thanks!

02-02-2007, 03:20 AM
Maybe you are going to hate yourself :D

if($ipaddr == $row['toip'])

02-02-2007, 03:24 AM
:eek: .........hate is byfar an understatement..... thxs :D