Click to See Complete Forum and Search --> : Help With MySQL


Jick
04-19-2004, 02:10 PM
Hello again guys,

I need help with a problem I've been having with php and mysql. What I want to do is get the users current ip address and then I want to compare it aginst the table in the db and if there is a match to their current ip I want it to look at the banned column of that row in the db and if the value is 'true' then I want to set a var in my php file to true but if it is a value of 'false' I want to set the var to false. I have some code below that I got from somewhere else that I've been trying to make work but it's not. Can anybody help me? Thanks! :D<?php
mysql_connect("mysqlserv","mysqluser","mysqlpass");
mysql_select_db("mysqldbname");

$ip = $_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT * FROM shout WHERE ip = '$ip'");
$r = mysql_fetch_array($result);
$banned = $r["banned"];

if ($banned = "true"){ $banned = "true"; } else if ($banned = "false"){ $banned = "false"; }
?>

crh3675
04-19-2004, 02:17 PM
Syntax is incorrect:


if ($banned = "true"){ $banned = "true"; } else if ($banned = "false"){ $banned = "false"; }


should be


if ($banned == "true"){ $banned = "true"; } else if ($banned == "false"){ $banned = "false"; }


And you really do not have to reiterate the variable. So just echo the value of $banned after your database query:



mysql_connect("mysqlserv","mysqluser","mysqlpass");
mysql_select_db("mysqldbname");

$ip = $_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT * FROM shout WHERE ip = '$ip'");
$r = mysql_fetch_array($result);
$banned = $r["banned"];

echo $banned;

Jick
04-19-2004, 02:51 PM
Thank you!

That stupid little syntax error was what was making it not function. Once again thank you. :D