...

View Full Version : Array help!



Digger3000
06-13-2005, 05:17 AM
I have a MySQL database with member info in it, including ip address. But I can't get this to work:


$query=mysql_query("select ipaddr from meminfo11");
$iparray=mysql_fetch_array($query);
$yourip=$_SERVER['REMOTE_ADDR'];
if(in_array($yourip, $iparray)) {
die("You're already a member.");
}

But for some reason it doesn't work. What's wrong?

Kid Charming
06-13-2005, 05:41 AM
mysql_fetch_array() only pulls one row of your result set per call. You'd be much better off just checking the ip directly against the database:



$query = "
SELECT
1
FROM
meminfo11
WHERE
ipaddr = '$yourip'";

$result = mysql_query($result) or die(mysql_error());

if( mysql_num_rows($result) == 0 )
{
die('you\'re already a member');
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum