I have tried numerous solutions and am not able to get my query to work.
I am trying to create a like system, which in the code will check that the item being liked exists, and has not already been liked.
I think I am close in my query, however I keep getting an error.
The variable "$this_is_liked" is predefined to the value "Yes", the variable "$liked_user_id" is predefined to the value of the logged in user (1 in this example), and then "$liked_item_id" is being pulled from the pms_inventory table, while I'm trying to have it check that the item id exists, and that it has not already been liked.
Below is my code, and then the error.
if(isset($_POST['type'], $_POST['itemid'], $_POST['liked'])) {
include_once('connectdb.php');
include_once('global.php');
$liked_item_id = (int)$_POST['itemid']; // Liked Item ID
$liked_user_id = (int)$_SESSION['id']; // User ID
$this_is_liked = $_POST['liked']; // Value of "Yes"
mysql_query("
INSERT INTO pms_inventory_likes
(
liked,
user_id,
item_id,
)
VALUES
(
SELECT
{$this_is_liked}, {$liked_user_id}, {$liked_item_id}
FROM pms_inventory
WHERE EXISTS (
SELECT id
FROM pms_inventory
WHERE id = {$liked_item_id})
AND NOT EXISTS (
SELECT id
FROM pms_inventory_likes
WHERE user_id = {$liked_user_id}
AND item_id = {$liked_item_id}
AND liked = 'Yes')
)
LIMIT 1
") or die(mysql_error());
}
Here is the error:
<span>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
VALUES
(
SELECT
Yes, 1, 40
FROM pms_inventory
' at line 6</span>
I am not sure if I am nesting "SELECT" correctly, or if I am labeling the values properly.
Please let me know if more info is needed!