Answer the question
In order to leave comments, you need to log in
How to combine INSERT with SELECT?
How to fix this script? I don't understand how to combine them?
if($_POST['message'] != ""){
$id_client = $_SESSION['id_client'];
$text = $_POST['message'];
$type = "2";
$data = date("Y-m-d H:i:s");
$status = "0";
$query = "INSERT INTO messages (id_dialog, text, type, data, status) SELECT
id_dialog, $text, $type, $data, $status
FROM dialogs WHERE id_client = '$id_client'";
$result = db_connection($query);
exit;
}
Answer the question
In order to leave comments, you need to log in
before executing the query, execute
and try to duplicate the query in any MySQL client, it will immediately become clear where the error is
There is no logic in the line SELECT id_dialog, $text, $type, $data, $status. You are trying to get a column with a name in a variable, for example $data. Each time it will be different values. It's easy to guess that you don't have a column for every millisecond of time))
It may be more correct to SELECT id_dialog, text, type, data, status - but no one will tell you what table you have, what this script should do, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question