Hello, I need some help here. I cannot make the right query.
In my code, I want to insert a data into my database. But the id_number will have different values. Id_number have different values because its from a group. So with that group of id_number I want to insert an action, to every id_number belonging in a same group.
So I want my db table to look like this after inserting data.
Actiondone || Date accomplish || idnumber || complaintid
========== || =============== || ========= ||==========
Done || 2014-01-01 || 201010005 || 1
========== || =============== || ========= ||==========
Done || 2014-01-01 || 20101178 || 2
========== || =============== || ========= ||==========
Done || 2014-01-01 || 201010023 || 3
Here is what I have now.
<?php
$con=mysqli_connect("localhost","root","root","sample6");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO admin_actions (action_done, date_accomplished, id_number, complaint_id)
SELECT id_number AS id, complaint_id AS cid FROM complaints WHERE group_id=1
VALUES('done','2014-01-16', 'id', 'cid')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>