更新查询不更新表

时间:2021-07-23 00:10:51

I am executing an update query in my script. It's returning true but the update query does not update the table. Here is the query. What i'm missing here?

我在我的脚本中执行更新查询。它返回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;
}

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 ;

5 个解决方案

#1


0  

what is the value of $booker_id, as i suspect that it is updating successfully but not actually matching the records. print out $query and see exactly what is being sent to the db

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

#2


0  

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

希望它会有所帮助

#3


0  

And the ` till on column name as you have column name date and date is a datatype of column and reserved keywork in mysql use this:

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

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

#4


0  

It returns true because there was no error.
But Mysql didn't find any entry to update, because none is corresponding to your conditions.
You should return the whole query to check it, and try to execute it by hand with phpMyAdmin.
+1 for the ` around the date column.

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

#5


0  

mysql_query() just returns true since the query run successfully. 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. Note: mysql_* queries are depricated, So Try to use any of PDO, mysqli

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

#1


0  

what is the value of $booker_id, as i suspect that it is updating successfully but not actually matching the records. print out $query and see exactly what is being sent to the db

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

#2


0  

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

希望它会有所帮助

#3


0  

And the ` till on column name as you have column name date and date is a datatype of column and reserved keywork in mysql use this:

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

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

#4


0  

It returns true because there was no error.
But Mysql didn't find any entry to update, because none is corresponding to your conditions.
You should return the whole query to check it, and try to execute it by hand with phpMyAdmin.
+1 for the ` around the date column.

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

#5


0  

mysql_query() just returns true since the query run successfully. 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. Note: mysql_* queries are depricated, So Try to use any of PDO, mysqli

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