dtmm0148603 2016-03-31 18:48
浏览 49

Mysqli第2行错误如何隔离'不影响文本区域之外的代码

I am getting an error code "error on line 2" regarding apostrophes. I think what is happening is in the text fields when a ' is typed it is effecting the code outside the "" and causing an error. How do i make marks within the text field not effect the remainder of the code?

the html elements in question are q25 and q35

The site is live at http://educationofthedesigner.com/survey.html after you submit it sends you to the php page.

error __

Error: INSERT INTO survey2 (Email, School, Major, Degree, Status, Sex, Age, Q7, Q8, Q9, Classes, 
       Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27, 
       Q28, Q29, Q30, Q31, Q32, Q33, Q34, Q35, Q36, Q37, Q38, Q39, Q40, Q41, Q42, Q43)

       VALUES ('', 'Purchase College', 'Graphic Design', 'BFA', 'Senior', 'Male', '1994', 'no', 
               'no', 'yes', 'branding, web/interactive, print, art direction, social design, 
               design theory, design authorship, type design, book arts, printmaking, 
               letterpress, design history', 'yes', '19 to 21', '11 to 20', 'no', '7', '3', 
               '1', '8', '2', '10', '3', '3', 'no', '30+', 'We don't focus on 
                skills/encouraging the development of a marketable portfolio at all. 
                There are students in my program who still don't understand basic precepts 
                of design, and more importantly don't understand how to teach themselves 
                new techniques. We're rooted in a homogenous visual culture that encourages 
                illiteracy in the tools of the trade as a hallmark of its style.', 'yes', 
               'studio', 'yes', 'yes', '20-25', '4', '2', '6', 'on capus', 'A drab closet 
               of a room filled with computers and devoid of windows and non-fluorescent 
               light. Big tables for cutting. No food or drink.', 'financial', 'yes', 'no', 
               '10', '7', 'yes', 'essential', 'Not Really')
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 't focus on skills/encouraging the development of 
a marketable portfolio at all. ' at line 2
  • 写回答

3条回答 默认 最新

  • dpauxqt1281 2016-03-31 18:56
    关注

    You just need to escape apostrophes inside values apostrophes with slashes

    INSERT INTO survey2 (Email, School, Major, Degree, Status, Sex, Age, Q7, Q8, Q9, Classes, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27, Q28, Q29, Q30, Q31, Q32, Q33, Q34, Q35, Q36, Q37, Q38, Q39, Q40, Q41, Q42, Q43) VALUES ('', 'Purchase College', 'Graphic Design', 'BFA', 'Senior', 'Male', '1994', 'no', 'no', 'yes', 'branding, web/interactive, print, art direction, social design, design theory, design authorship, type design, book arts, printmaking, letterpress, design history', 'yes', '19 to 21', '11 to 20', 'no', '7', '3', '1', '8', '2', '10', '3', '3', 'no', '30+', 'We don\'t focus on skills/encouraging the development of a marketable portfolio at all. There are students in my program who still don\'t understand basic precepts of design, and more importantly don\'t understand how to teach themselves new techniques. We\'re rooted in a homogenous visual culture that encourages illiteracy in the tools of the trade as a hallmark of its style.', 'yes', 'studio', 'yes', 'yes', '20-25', '4', '2', '6', 'on capus', 'A drab closet of a room filled with computers and devoid of windows and non-fluorescent light. Big tables for cutting. No food or drink.', 'financial', 'yes', 'no', '10', '7', 'yes', 'essential', 'Not Really')
    

    A basic example

    INSERT INTO table (a, b, c) VALUES (1, 'hello', 'don\'t know');
                                                     -- ^ note the slash here
    

    Or otherwise you can use php functions to deal with apostrophes as addslashes()

    The errors occurs because mysql end the string to the first apostrophe found after the opening one for any values, the rest of the string will be not surrounded with apostrophe.

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3