Update Row If IP = IP in database
Moderator: General Moderators
echo $id and $ip
i'll bet you one of those isn't set
i'll bet you one of those isn't set
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
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);
?>Ok, I'm trying to see what you're doing here
I think this should do the same thing, try it :{]
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);
?>- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
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);
?>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).
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).
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
The code now is
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
<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);
?>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 ;