Page 2 of 3

Posted: Sun Oct 22, 2006 3:10 pm
by s.dot
echo $id and $ip

i'll bet you one of those isn't set

Posted: Sun Oct 22, 2006 3:11 pm
by nickman013
They both are.

Posted: Sun Oct 22, 2006 3:12 pm
by Flamie
naa if they're not set they shouldnt do an error, just put in a blank value AFAIK.

Post your current code again please, you've probably changed a lot in it.

Posted: Sun Oct 22, 2006 3:15 pm
by nickman013
The code as of now is

Code: Select all

<font color=white>
<? 
$username= "muot_report";  
$password= "report";  
$database= "muot_report";  
$connection = mysql_connect('localhost',$username,$password);  
mysql_select_db($database); 

$id = $_POST['id']; 
$ip = $_POST['ip']; 

$result = mysql_query("SELECT * FROM `comments` WHERE `ip` = '$ip'") or die(mysql_error()); 
while($row = mysql_fetch_array($result)) 
{ 
        if($ip == $row['ip']) 
        { 
                mysql_query("UPDATE `comments` set `show` = 0 WHERE `id` = $id") or die(mysql_error()); 
        } 
} 
mysql_close($connection); 
?>

Posted: Sun Oct 22, 2006 3:16 pm
by reecec
sorry my comment about == wont solve your error but is still needed for what you want


sorry i have no ideas for the error

thanks reece

Posted: Sun Oct 22, 2006 3:20 pm
by Flamie
Ok, I'm trying to see what you're doing here

Code: Select all

<font color=white>
<?
$username= "muot_report"; 
$password= "report"; 
$database= "muot_report"; 
$connection = mysql_connect('localhost',$username,$password); 
mysql_select_db($database);

$id = $_POST['id'];
$ip = $_POST['ip']; 

mysql_query("UPDATE `comments` SET `show`=0 WHERE `ip`='$ip' AND `id`=$id") or die(mysql_error());
mysql_close($connection);
?>
I think this should do the same thing, try it :{]

Posted: Sun Oct 22, 2006 3:21 pm
by nickman013
Same error with that code too..

Posted: Sun Oct 22, 2006 3:22 pm
by Flamie
Ok, check yoru fields in the database, are they called like that? Thats the only thing I can think of...

Posted: Sun Oct 22, 2006 3:23 pm
by Flamie
Also, show is an integer type right?

Posted: Sun Oct 22, 2006 3:23 pm
by nickman013
CHAR

Posted: Sun Oct 22, 2006 3:24 pm
by Flamie
hahaha
then do `show`='0'

Posted: Sun Oct 22, 2006 3:25 pm
by nickman013
Now Its INT and it doenst work still.

Posted: Sun Oct 22, 2006 3:26 pm
by Flamie

Code: Select all

<font color=white>
<?
$username= "muot_report";
$password= "report";
$database= "muot_report";
$connection = mysql_connect('localhost',$username,$password);
mysql_select_db($database);

$id = $_POST['id'];
$ip = $_POST['ip'];
echo "id: ".$id."<br>ip: ".$ip."<br>";
mysql_query("UPDATE `comments` SET `show`=0 WHERE `ip`='$ip' AND `id`=$id") or die(mysql_error());
mysql_close($connection);
?>
whast the full ouput of this script?

Posted: Sun Oct 22, 2006 3:27 pm
by timvw
Flamie beat me to it..

couple of remarks though: validate your user input... Don't use it 'as is' in your query...
And an ip-address is simply a number, unsigned int(10) seems a more appropriate type for the column than a varchar.. (lookup the inet_aton and inet_ntoa functions in your mysql manual).

Posted: Sun Oct 22, 2006 3:27 pm
by nickman013
The code now is

Code: Select all

<font color=white>
<? 
$id = $_POST['id']; 
$ip = $_POST['ip']; 

$username= "muot_report"; 
$password= "report"; 
$database= "muot_report"; 
$connection = mysql_connect('localhost',$username,$password); 
mysql_select_db($database); 


mysql_query("UPDATE `comments` SET `show`=0 WHERE `ip`='$ip' AND `id`=$id") or die(mysql_error()); 
mysql_close($connection); 
?>
The error is

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1



My database structure is

Code: Select all

CREATE TABLE `comments` (
  `id` int(99) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `comment` text NOT NULL,
  `who` int(99) NOT NULL default '0',
  `ip` varchar(50) NOT NULL default '0',
  `show` int(2) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1040 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1040 ;