/    Sign up×
Community /Pin to ProfileBookmark

Help With MySQL

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! ?

[code=php]<?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”; }
?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 19.2004 — Syntax is incorrect:

<i>
</i>if ($banned = "true"){ $banned = "true"; } else if ($banned = "false"){ $banned = "false"; }


should be

<i>
</i>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:

<i>
</i>
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;

Copy linkTweet thisAlerts:
@JickauthorApr 19.2004 — Thank you!

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

Success!

Help @Jick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...