dongzhuo3202 2016-07-02 12:06
浏览 23
已采纳

mysql无法插入包含8列的表中

i'm trying to insert datas in a table of 8 columns but it's doesn't work . i'm using mysql version 5.7.11 . however it works when i reduce it to 6 columns 7 columns refuse to work as well .

please find the tables and their php code below

  1. 6 columns mysql/php

1.1 php

$res=$pdo->prepare('INSERT INTO '.$table.'(title,description,image,city,price) VALUES(:titl,:decri,:img,:cty,:prce)');

$res->bindParam(':titl',$title);
     $res->bindParam(':decri',$decri);
     $res->bindParam(':img',$item_img);
     $res->bindParam(':cty',$city);
     $res->bindParam(':prce',$price);

1.2 mysql

 CREATE TABLE `mobiles` 
 (`id` int(11) NOT NULL,
 `title` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
 `description` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`image` longblob NOT NULL,
`city` varchar(20) NOT NULL,
`price` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1. 8 columns tables

2.1 mysql code

  CREATE TABLE `mobiles` (
 `id` int(11) NOT NULL,
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT   NULL,
 `image` longblob NOT NULL,
`city` varchar(20) NOT NULL,
`price` int(11) NOT NULL,
`user_id` int(10) NOT NULL,
`date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

2.2 php code

$res=$pdo->prepare('INSERT INTO'.$table.'(title,description,image,city,price,user_id,date)    VALUES(:titl,:decri,:img,:cty,:prce,:user_id,:dte)');
     $res->bindParam(':titl',$title);
     $res->bindParam(':decri',$decri);
     $res->bindParam(':img',$item_img);
     $res->bindParam(':cty',$city);
     $res->bindParam(':prce',$price);
     $res->bindParam(':user_id',$user_id);
     $res->bindParam(':dte',$date);

i have executed right after , the six columns works but the 8 columns one

why is that more than 6 columns mysql can't insert while the number limit of columns can reach 255.

is there any issue in my code ? i echoed all the entries and they all work fine.

any help please ?

  • 写回答

1条回答 默认 最新

  • duanbei3747 2016-07-02 12:24
    关注

    You have no space between 'INSERT INTO' and $table in second query, so query fails because of syntax error.

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

报告相同问题?

悬赏问题

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