Mysql 语法错误? [英] Wrong syntax for Mysql?

查看:61
本文介绍了Mysql 语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$SQL="SELECT first_name FROM people WHERE fname = '$fname' INSERT INTO (first_name) VALUES (fname)";

这有什么问题吗?试图将用户定义的变量中的值插入到 mysql 表中

Anything wrong with this? Trying to insert a value from a user defined variable into a mysql table

警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 44 行 D:\wamp\www\Pxxxx\process.php 中给出

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\wamp\www\Pxxxx\process.php on line 44

这是错误

$fname 是用户定义的变量first_name 是我试图将其插入的列,它位于名为 people 的表中

$fname is a user defined variable first_name is the column I'm trying to insert it into and it's in a table called people

推荐答案

您的顺序颠倒了.看起来您正在寻找 INSERT .. SELECT 语法(请参阅此处的 MySQL 文档:http://dev.mysql.com/doc/refman/5.6/en/insert-select.html)

You have the order inverted. It seems like you are looking for INSERT .. SELECT syntax (see MySQL documentation here: http://dev.mysql.com/doc/refman/5.6/en/insert-select.html)

INSERT INTO target_table (first_name)
SELECT fname
FROM people
WHERE fname = ?

从您的示例中不清楚您尝试向其中插入数据的表的名称是什么,所以我在此处将其列为 target_table.

It was unclear from your example what the name of the table you were trying to insert data into is, so I just listed it as target_table here.

这篇关于Mysql 语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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