更新查询不更新表

时间:2013-08-05 08:56:23

标签: php mysql

我正在我的脚本中执行更新查询。它返回true但更新查询不更新表。这是查询。我在这里缺少什么?

$connection = db::factory('mysql');
$query='update bookings SET date="'.$date.'",time_from="'.$time_from.'",time_to="'.$time_to.'",status="'.$status.'" where booker_id="'.$booker_id.'"';
if(mysql_query($query)) {
   echo "success"; exit;
   return true;
} else {
   echo "fail"; exit;
   return false;
}

这是表结构

CREATE TABLE IF NOT EXISTS `bookings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `time_from` time NOT NULL,
  `time_to` time NOT NULL,
  `status` varchar(250) NOT NULL,
  `booker_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;

5 个答案:

答案 0 :(得分:0)

试试这个:

 $query='update `bookings` SET `date`="'.$date.'",`time_from`="'.$time_from.'",`time_to`="'.$time_to.'",`status`="'.$status.'" where `booker_id`="'.$booker_id.'"';


    $rs = mysql_query($query) or die(mysql_error());

    if($rs) {
       echo "success"; exit;
       return true;
    } else {
       echo "fail"; exit;
       return false;
    }

希望它会有所帮助

答案 1 :(得分:0)

并且`列的名称,因为你有列名日期和日期是列的数据类型和mysql中保留的keywork使用这个:

$query='update `bookings` SET `date`="'.$date.'",`time_from`="'.$time_from.'",`time_to`="'.$time_to.'",`status`="'.$status.'" where `booker_id`="'.$booker_id.'"';

答案 2 :(得分:0)

它返回true,因为没有错误 但Mysql没有找到任何更新的条目,因为没有条件符合您的条件 您应该返回整个查询以进行检查,并尝试使用phpMyAdmin手动执行它 日期栏周围的`+1。

答案 3 :(得分:0)

$booker_id的值是多少,因为我怀疑它是成功更新但实际上没有匹配记录。打印出$query并查看发送到数据库的确切内容

答案 4 :(得分:0)

mysql_query()只是在查询成功运行后才返回true。我建议更新/修改行数以检查此查询是否更新了任何行。因此,在执行更新查询后立即使用mysql_affected_rows()。 注意:mysql_ *查询已被删除,因此请尝试使用PDOmysqli

中的任何一个
相关问题