drbi19093 2014-10-17 14:40
浏览 44
已采纳

您的SQL语法有错误 - 无法找到错误[关闭]

I seems to have a sytax error within my code but cannot see why.

the line in question is here:

mysqli_query($db,"INSERT INTO `horses` (`ParentID`,`Date`,`Track`,`Runners`, `Going`, `Distance`,`Class`,`Place`,`Losing_Dist`,`Stall`,`Horse`,`Weight`,`Trainer`,`Odds`,`Oddsmovement`,`Jockeys_Claim`,`Comments`,`Race_Name` )VALUES  ('$id ',' $Thedate','$thecourse','$noinrace','$going','$distance','$class','$place','$distance_bt','$stall','$horse','$weight','$thetrainer','$odds','$oddsmovement','$thejockey','$comments','$event')")or die(mysqli_error($db));

And the full error i get is here

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 'Meara ',' 22/1 ','25/1 < 22/1','D Nolan','',' Royal Marines ' at line 1

The line in which it says is near is this: '$thetrainer','$odds','$oddsmovement','$thejockey'

the database is set so all fields are varchat(250) aparent from parent id and id which are int

any further information please let me know

  • 写回答

1条回答 默认 最新

  • doupiao9318 2014-10-17 15:29
    关注

    This should work if the values in your PHP variables are valid:

    mysqli_query($db,"INSERT INTO horses (Date,Track,Runners,Going,Distance,Class,Place,Losing_Dist,Stall,Horse,Weight,Trainer,Odds,Oddsmovement,Jockeys_Claim,Comments,Race_Name) VALUES  ({$Thedate},{$thecourse},{$noinrace},{$going},{$distance},{$class},{$place},{$distance_bt},{$stall},{$horse},{$weight},{$thetrainer},{$odds},{$oddsmovement},{$thejockey},{$comments},{$event})")or die(mysqli_error($db));
    

    Like mentioned in the comments above if this is a public page you should protect again SQL injection there are several techniques just google it if you aren't sure how.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化