简体   繁体   English

更新查询不更新表

[英]update query not updating the table

I am executing an update query in my script. 我正在脚本中执行更新查询。 It's returning true but the update query does not update the table. 它返回true,但update查询不会更新表。 Here is the query. 这是查询。 What i'm missing here? 我在这里想念的是什么?

$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;
}

Here is the table structure 这是表格结构

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 ;

Try this : 尝试这个 :

 $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;
    }

Hope it will help 希望对你有帮助

和`直到列名的直到字段名称和日期一样,直到字段是列的数据类型,并且在MySQL中保留键使用以下命令:

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

It returns true because there was no error. 它返回true,因为没有错误。
But Mysql didn't find any entry to update, because none is corresponding to your conditions. 但是Mysql找不到任何要更新的条目,因为没有一个与您的条件相对应。
You should return the whole query to check it, and try to execute it by hand with phpMyAdmin. 您应该返回整个查询以进行检查,并尝试使用phpMyAdmin手动执行它。
+1 for the ` around the date column. 为日期栏周围的+1。

what is the value of $booker_id , as i suspect that it is updating successfully but not actually matching the records. $booker_id的值是$booker_id ,因为我怀疑它已成功更新,但实际上与记录不匹配。 print out $query and see exactly what is being sent to the db 打印$query并确切地看到什么被发送到数据库

mysql_query() just returns true since the query run successfully. 由于查询成功运行, mysql_query()仅返回true。 I would recommend to get the number of rows updated/modified to check whether this query updated any row or not. 我建议获取更新/修改的行数,以检查此查询是否更新了任何行。 So use mysql_affected_rows() immediately after executing update query. 因此,在执行更新查询后立即使用mysql_affected_rows() Note: mysql_* queries are depricated, So Try to use any of PDO , mysqli 注意:mysql_ *查询已描述,因此请尝试使用PDOmysqli中的任何一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM