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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog