Ciao a tutti,
sto perdendo del tempo su un problema apparentemente idiota ossia sto cercando di aggiornare certe righe di una tabella con determinati valori. Il codice che uso è il seguente
Codice PHP:
$query = "UPDATE `my_codx`.`admin_pages` SET `active` = CASE `admin_pages`.`display` ";
$in = array();
foreach($_POST as $k => $v){
$query .= "WHEN '$k' THEN ".($v == "on" ? 1 : 0)." ";
$in[] = "'$k'";
}
$rank = rank();
$name = name();
$query .= "END WHERE `admin_pages`.`display` IN (".implode(",",$in).") AND `admin_pages`.`min_rank` <= $rank LIMIT ".count($in);
if(mysql_query($query, $db) == false)
$_SESSION['error'] = "
".SQL_ERROR."</p>";
else
$_SESSION['notify'] = "
Pages updated successfully. A log line was created.</p>";
che produce (riportata tramite echo) la seguente query (ad esempio)
codice:
UPDATE `my_codx`.`admin_pages` SET `active` = CASE `admin_pages`.`display` WHEN 'Add_pagE' THEN 1 WHEN 'Feedback_managemenT' THEN 1 END WHERE `admin_pages`.`display` IN ('Add_pagE','Feedback_managemenT') AND `admin_pages`.`min_rank` <= 9 LIMIT 2
Ne da script php ne da phpMyAdmin da errori eppure in entrambi i casi mi dice che nessuna riga è stata influenzata... e proprio mi sfugge il motivo!!
Qualcuno mi potrebbe aiutare per favore?
Lascio il dump della tabella, magari aiuta:
codice:
CREATE TABLE IF NOT EXISTS `admin_pages` (
`id` int(2) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique ID for each different page assigned automatically.',
`display` varchar(30) NOT NULL COMMENT 'Name for each admin page.',
`min_rank` int(1) unsigned NOT NULL COMMENT 'Minimum rank for accessing a page.',
`active` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'If active (non-zero) the page is listed in the control panel for allowed users',
`file` varchar(128) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL COMMENT 'The HTML content of the page.',
`time` bigint(11) NOT NULL COMMENT 'Timestamp of when the page was added.',
PRIMARY KEY (`id`),
UNIQUE KEY `display` (`display`),
UNIQUE KEY `require` (`file`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of admin pages.' AUTO_INCREMENT=4 ;
INSERT INTO `admin_pages` (`id`, `display`, `min_rank`, `active`, `file`, `time`) VALUES
(1, 'Add pagE', 4, 1, 'admin-addpage.php', 1348949558),
(2, 'Feedback managemenT', 3, 0, 'feedback-management.php', 1359902634),
(3, 'Pages statuS', 5, 1, 'page-status.php', 1360167089);