0

hi i'm having difficulty trying to insert multiple row of data where userid = deviceid (Which will be taken from the .php URL)

e.g. 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

Here's an example

Message | userid

hi | john

hi | mary

hi | Jake

etc..

please help me.. i'll do my best to reply

thanks

1 Answer 1

1
INSERT INTO notif (message,userid)
  SELECT 'Hi', user_id 
  FROM devices WHERE
   deviceid = :deviceid 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.