使用INSERT将Integer值插入mysql int [英] Inserting Integer value into mysql int using INSERT

查看:118
本文介绍了使用INSERT将Integer值插入mysql int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在PHP的MySQL数据库中插入一条新记录,我之前已经做了一百万次,但出于某种原因,这次我无法让它工作,这真的让我烦恼。

I'm trying to insert a new record in a MySQL database from PHP, which I've done a million times before, but for some reason, I can't get it to work this time, and it really bugs me.

在所有varchar列中插入字符串都很棒,但是当我在int列中插入一个值时,我得到一个错误,告诉我我有一个语法错误。

Inserting strings into all the varchar collumns are going great, but when I get to inserting a value into the int column, I get an error telling me that I have a syntax error.

基本上,第一个查询工作正常,但第二个查询返回错误,正如您所看到的,我已经确定它确实是我试图插入的整数。

Basically, the first query works just fine, but the second one returns the error, and as you can see, I've made damn sure it really is an integer I'm trying to insert.

我希望有人可以提供帮助。我真的开始对此感到头疼:/

I hope somebody can help. I'm really starting to develop a headache over this :/

$groupId2 = 5;
$groupId = (int)$groupId2;
if(!mysqli_query($link, "INSERT INTO contestants (firstName, lastname, email) VALUES ('$firstName', '$lastName', '$email')"))
  echo "First: " . mysqli_error($link);
if(!mysqli_query($link, "INSERT INTO contestants (firstName, lastname, email, group) VALUES ('$firstName', '$lastName', '$email', '$groupId')"))
  echo "Second: " . mysqli_error($link);


推荐答案

group 是一个mysql关键字,使用它后面的引号

group is a mysql keyword use back quotes around it

"INSERT INTO contestants (firstName, lastname, email, `group`) 
 VALUES ('$firstName', '$lastName', '$email', '$groupId')"

这篇关于使用INSERT将Integer值插入mysql int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆