查询在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.

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.

PHP doesn't always play nice when you try to cast variables in string concatenation. You're also treating an integer as a string for customer_id.

Try this:

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

As a side note, it's very bad security practice to inject variables into an SQL query like that. You should use parameters to avoid SQL injection attacks.

I run your code and found nothing wrong, my row was updated successfully with status and approved both fields.

but I will suggest you not to typecast your variables to integer because when you are typecasting them to integer at the same time you are concatenating them to a string which finally resulting in a string only so no need to typecast only make sure that you provide valid values to those variables through PHP, try following statement and revert if problem solved.

$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=$status,approved=$approved,date_added='$date_added1',discount=$discount WHERE customer_id='$customer_id'";