在php中使用Insert、Select和values
您好,我在尝试插入多行数据时遇到困难,其中userid=deviceid将从.php URL获取 e、 g.url.com/test/this.php?deviceid=abc 这是我的代码:在php中使用Insert、Select和values,php,mysql,Php,Mysql,您好,我在尝试插入多行数据时遇到困难,其中userid=deviceid将从.php URL获取 e、 g.url.com/test/this.php?deviceid=abc 这是我的代码: $sql = "INSERT INTO notif (message,userid) VALUES ('hi', (select userid from devices where deviceid = '" . $deviceid . "'))"; if ($conn->query($sql)
$sql = "INSERT INTO notif (message,userid) VALUES ('hi', (select userid from devices where deviceid = '" . $deviceid . "'))";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
主要目标是,我希望数据库也能插入带有“hi”消息的用户数量
这里有一个例子
消息|用户ID
嗨,约翰
嗨,玛丽
嗨|杰克
等等
请帮帮我。。我会尽力回答的
谢谢
INSERT INTO notif (message,userid)
SELECT 'Hi', user_id
FROM devices WHERE
deviceid = :deviceid