doujiang1993 2016-09-09 05:17
浏览 59
已采纳

查询在phpmyadmin中工作,但在PHP脚本中不起作用

I know this is very silly question. But I am disappointed with the behaviour of this query. I am updating Customers in Opencart. When I have written and executed an Update query, few fields are being inserted and few are not. Especially I need to update 'status' and 'approved' columns. Please check the below Query.

UPDATE oc_customer SET customer_group_id=1,store_id=0,firstname='',lastname='HEATHER HUME',telephone='9876543210',fax='0',password='f53cbb1352950831a84035d320063383f345cfce',salt='rCF2EquoV',status='1',approved='1',date_added='2016-08-31',discount=62.00 WHERE customer_id='1418'

Please let me know what is wrong with this. It is updating Telephone column and not status,approved.

Below is the structure of my table

CREATE TABLE IF NOT EXISTS `oc_customer` (
  `customer_id` int(11) NOT NULL,
  `customer_group_id` int(11) NOT NULL,
  `store_id` int(11) NOT NULL DEFAULT '0',
  `firstname` varchar(32) NOT NULL,
  `lastname` varchar(32) NOT NULL,
  `email` varchar(96) NOT NULL,
  `telephone` varchar(32) NOT NULL,
  `cellphone` varchar(32) NOT NULL,
  `fax` varchar(32) NOT NULL,
  `password` varchar(40) NOT NULL,
  `salt` varchar(9) NOT NULL,
  `cart` text,
  `wishlist` text,
  `newsletter` tinyint(1) NOT NULL DEFAULT '0',
  `address_id` int(11) NOT NULL DEFAULT '0',
  `custom_field` text NOT NULL,
  `ip` varchar(40) NOT NULL,
  `status` tinyint(1) NOT NULL,
  `approved` tinyint(1) NOT NULL,
  `safe` tinyint(1) NOT NULL,
  `token` text NOT NULL,
  `date_added` datetime NOT NULL,
  `discount` decimal(8,2) NOT NULL DEFAULT '0.00',
  `tax_id` varchar(50) NOT NULL,
  `subscribe` varchar(5) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=1419 DEFAULT CHARSET=utf8;

My php code is

$query = "UPDATE oc_customer SET customer_group_id=1,store_id=0,firstname='$first_name',lastname='$last_name',telephone='$phone',fax='$fax',password='$password',salt='$salt',status=".(int)$status.",approved=".(int)$approved.",date_added='$date_added1',discount=$discount WHERE customer_id='$customer_id' ";
mysqli_query($con,$query);

$con is my connection variable.No problem with that.

  • 写回答

3条回答 默认 最新

  • dongsheng8158 2016-09-12 06:08
    关注

    Thanks for your response. There is no problem with the query. The problem is with special characters which we can't see either in our editors or in PhpMyAdmin. This may be helpful for someone who have stuck with same problem, i.e., Query executes in PhpMyAdmin and not in PHP Script.

    Please type the query on your own. Please don't copy and paste it from anywhere. Not atleast from your own page again.
    

    Please type everything on your own because copy paste may again copy the invisible special characters into query which again makes your query tough to debug.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题