So, I'm trying to achieve a dynamic htaccess ban system, and this line of code is causing me huge problems:
$ip = mysql_query("SELECT ID FROM wp_contactform WHERE Nimi='Christian'");
When I echo it out, it gives me the following:
Resource id #3
The table contains Christian 3 times, with id's 11, 13 and 10. What's causing this?
$ip = mysql_query("SELECT ID FROM wp_contactform WHERE Nimi='Christian'");
$ip
will simply retrieve the resource representing the resultset - it is not the data itself.
You will need to look into using:
$ip_array = mysql_fetch_array($ip);
$ID = $ip_array['ID'];
to get the ID
.
Also keep in mind that this API (mysql_*)
is deprecated, so it may be in your best interests to look into alternative MySQL libraries in PHP:
MySQLi: http://php.net/manual/en/book.mysqli.php
MySQL PDO: http://php.net/manual/en/book.mysqli.php
clearly written in manual
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
while ($row = mysql_fetch_assoc($ip))
{
echo $result[] = $row;
}
echo "<pre>";
print_r($result);