Page 1 of 1

stupid mysql 5 connect issue??? dumbfounded :-)

Posted: Mon Mar 31, 2008 1:35 pm
by blogscrubber

Code: Select all

 
 
$ip = getenv(REMOTE_ADDR);
mysql_query("INSERT INTO `".$config['db']['pre']."banip` ( `user_ip` ) VALUES ( `$ip` )");
 
 
the code above is not inserting the ip in the field banip all other mysql_query statement like above in my site work fine, but this one is a ******.... thanks for any advice

Re: stupid mysql 5 connect issue??? dumbfounded :-)

Posted: Mon Mar 31, 2008 1:53 pm
by Zoxive

Code: Select all

mysql_query("INSERT INTO `".$config['db']['pre']."banip` ( `user_ip` ) VALUES ( `$ip` )") or die("You had an Error in your Mysql Code: <br/>\n" . mysql_error());
Always debug....

What looks suspicious is the field you are inserting into. You are using $config['db']['pre'] as part of the name.

Re: stupid mysql 5 connect issue??? dumbfounded :-)

Posted: Mon Mar 31, 2008 2:05 pm
by blogscrubber
umm... i got this message after i updated the code with the code you posted?

there is a field user_id in the table banip... not sure what's going on!

You had an Error in your Mysql Code:
Unknown column '192.168.1.100' in 'field list'

Re: stupid mysql 5 connect issue??? dumbfounded :-)

Posted: Mon Mar 31, 2008 2:53 pm
by blogscrubber
the code below is what i'm trying to get working... i've almost got it but it's being kinda stubborn!

Code: Select all

 
 
$viewed = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."banip WHERE user_id='".validate_input($_GET['i'])."' AND user_ip='".validate_input(ip2long($user_ip))."' LIMIT 1"));
        
if(!$viewed)
{
mysql_query("INSERT INTO `".$config['db']['pre']."banip` ( `user_ip` , `user_id` ) VALUES ( '".validate_input(ip2long($ip))."' , user_id='".validate_input($_GET['i'])."' )") or die("You had an Error in your Mysql Code: <br/>\n" . mysql_error());
} 
else
{
mysql_query("UPDATE `".$config['db']['pre']."users` SET `views` = views+1 WHERE `user_id`=".addslashes($_GET['id'])." LIMIT 1;");
mysql_query("UPDATE ".$config['db']['pre']."banip SET `user_id` = '".validate_input($_GET['id'])."' WHERE user_ip='".validate_input(ip2long($user_ip))."'");
} 
 
 
please help i've spent the last two hours working on this dumb thing!!!! thanks

Re: stupid mysql 5 connect issue??? dumbfounded :-)

Posted: Mon Mar 31, 2008 3:05 pm
by blogscrubber
thank you for your help... i had to remove the or die to get it working... there's supposed to be a duplicate entry as it updates the user id each time based on the ip address! works perfect!

Code: Select all

 
 
mysql_query("UPDATE ".$config['db']['pre']."banip SET `user_id` = '".validate_input($_GET['id'])."' WHERE user_ip='".validate_input(ip2long($user_ip))."'");
$viewed = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."banip WHERE user_id='".validate_input($_GET['i'])."' AND user_ip='".validate_input(ip2long($user_ip))."' LIMIT 1"));
        
if(!$viewed)
{
 
} 
else
{
mysql_query("INSERT INTO `".$config['db']['pre']."banip` ( `user_ip` , `user_id` ) VALUES ( '".validate_input(ip2long($ip))."' , user_id='".validate_input($_GET['i'])."' )");
mysql_query("UPDATE `".$config['db']['pre']."users` SET `views` = views+1 WHERE `user_id`=".addslashes($_GET['id'])." LIMIT 1;");
}