简体   繁体   English

在PHP中使用插入,选择和值

[英]Using Insert, Select and values in php

hi i'm having difficulty trying to insert multiple row of data where userid = deviceid (Which will be taken from the .php URL) 嗨,我在尝试插入多行数据时遇到困难,其中userid = deviceid(将从.php URL中获取)

eg url.com/test/this.php?deviceid=abc 例如url.com/test/this.php?deviceid=abc

This are my code: 这是我的代码:

$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;
}

The main goal is that i want the database to insert the amount of users with the message of 'hi' as well 主要目标是我也希望数据库在用户数量中插入“ hi”消息

Here's an example 这是一个例子

Message | 留言| userid 用户身份

hi | 你好 john 约翰

hi | 你好 mary 玛丽

hi | 你好 Jake 可靠的人

etc.. 等等..

please help me.. i'll do my best to reply 请帮助我..我会尽力答复

thanks 谢谢

INSERT INTO notif (message,userid)
  SELECT 'Hi', user_id 
  FROM devices WHERE
   deviceid = :deviceid 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM