문제

Anyone know how to insert "/" character into a string in mysql. I have a varchar field with 255 space. but when I insert a a string contain "1403/04". it is throwing an error.

EDIT: Here is my sql statement, I am using navicat to do the admin

INSERT INTO po values(1022,162,10221000339997,'05394906',
  '1403/04 BS BTM102-96 CORE S/SLV PTD TEE',,'',60.00,10.5,25,
  '2014-03-10','2014-03-03')
도움이 되었습니까?

해결책

This is the insert statement you provided in your comment:

INSERT INTO po values(1022,162,10221000339997,'05394906','1403/04 BS BTM102-96 CORE S/SLV PTD TEE',,'',60.00,10.5,25,'2014-03-10','2014-03-03')

And the error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''',60.00,10.5,25,'2014-03-10','2014-03-03')' at line 1

The problem is not the string with slashes. The problem is the double commas after that string. Either remove a comma, put something in between the two commas, or change your INSERT to explicitly list out the columns you are inserting (which you should do anyway, for clarity and to reduce bug potential) and exclude the one that corresponds to the spot between the two commas.

다른 팁

Try mysql_real_escape_string()

$input="1403/04";

INSERT INTO TABLE (table) VALUES ($input)

Note: Mysql is deprecated as of PHP 5.5 so use mysqli instead.

I am using cellphone so I will request someone to format my answer

Table Create Table


CREATE TABLE `posts` (                                   
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,         
      `title` varchar(50) DEFAULT NULL,                      
      `body` text,                                           
      `created` datetime DEFAULT NULL,                       
      `modified` datetime DEFAULT NULL,                      
      PRIMARY KEY (`id`)                                     
    ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1  

Now the insert query will work.

INSERT INTO posts (title, body) VALUES ("special", "366/88");
                             OR
INSERT INTO posts (title, body) VALUES ('special', '366/88');

Both will work. .................................................................................................................................................................... If you are using PHP It's better to use mysql_real_escape_string();

mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement

You should look here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top