Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQL插入选择问题_Mysql_Select_Insert - Fatal编程技术网

MYSQL插入选择问题

MYSQL插入选择问题,mysql,select,insert,Mysql,Select,Insert,我有点难以理解如何做一些插入选择 例如,我有两张桌子 TABLE : users id | name | gender 1 | John | m 2 | Mary | f TABLE : website fid | url | id 1 | www.desilva.biz | 2 2 | gidhelp.com | 4 现在让我们假设我想向表网站添加另一个查询。我得到两个变量,假设: $u

我有点难以理解如何做一些插入选择

例如,我有两张桌子

TABLE : users  

 id | name   | gender  
 1  | John   | m  
 2  | Mary   | f  

TABLE : website  

 fid | url             | id  
 1   | www.desilva.biz | 2  
 2   | gidhelp.com     | 4  
现在让我们假设我想向表网站添加另一个查询。我得到两个变量,假设:

$user = John;
$site = "www.google.com";
我想从users表中选择John的id,并在一条语句中将其插入到website表中


我该怎么做呢?

假设您的变量已经正确转义,并且没有进行
SQL
注入:

INSERT
INTO    website (url, fid)
SELECT  $site, id
FROM    users
WHERE   name = $user

我会引用至少$user,以便它在包含空格的名称上正确匹配。