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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blogscrubber
Forum Newbie
Posts: 5
Joined: Sun May 27, 2007 5:55 pm

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

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

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

Post 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.
blogscrubber
Forum Newbie
Posts: 5
Joined: Sun May 27, 2007 5:55 pm

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

Post 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'
blogscrubber
Forum Newbie
Posts: 5
Joined: Sun May 27, 2007 5:55 pm

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

Post 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
blogscrubber
Forum Newbie
Posts: 5
Joined: Sun May 27, 2007 5:55 pm

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

Post 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;");
} 
 
 
Last edited by onion2k on Mon Mar 31, 2008 3:14 pm, edited 1 time in total.
Reason: Don't post all in CAPS. It makes mods (well, me) want to do bad things.
Post Reply