I'm at odds. My SQL query will only send via PhpMyAdmin. If I attempt to send this specific query via PHP, I get an error. When I copy that exact query into PhpMyAdmin, it goes through without a problem.
INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('12056242', 'OMG I just got a #toyota', 'Clunker5', '09/12/14 08:43:36', 'toyota');INSERT INTO `tags` (tag, posts) VALUES ('toyota', 1) ON DUPLICATE KEY UPDATE posts=posts+1; UPDATE `tags` SET posts=posts+1 WHERE tag IN ('toyota');
This is the PHP code relevant to the issue
//Ups one post for all tags entered by the user
if(!empty($tags)){
$tags1 = explode(",", $tags);
$tags_submit = join("','", $tags1);
$tags_insert = join("', 1), ('", $tags1);
$sql = "INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('$d', '$b', '".$_SESSION['username']."', '$c', '$tags');"
. "INSERT INTO `tags` (tag, posts) VALUES ('".$tags_insert."', 1)
ON DUPLICATE KEY UPDATE posts=posts+1;
UPDATE `tags` SET posts=posts+1 WHERE tag IN ('".$tags_submit."');";
$result = mysql_query($sql);
}else{
$sql = "INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('$d', '$b', '".$_SESSION['username']."', '$c', '$tags');";
$result = mysql_query($sql);
}
$error = mysql_error();
if($result){
echo "1";
}else{
echo error($sql, $error, "Tags: ".$tags, "Post: ".$b, "ID: ".$d);
}
The error is
SQL Response: 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 'INSERT INTO `tags` (tag, posts) VALUES ('toyota', 1), ('ohmygoodness', 1) ' at line 1.
EDIT: Now that I know that I cannot do a multi-query, how can i do this query?
INSERT INTO `tags` (tag, posts) VALUES ('".$tags_insert."', 1)
ON DUPLICATE KEY UPDATE posts=posts+1;
UPDATE `tags` SET posts=posts+1 WHERE tag IN ('".$tags_submit."');
INSERT INTO tags (tag, posts) VALUES ('toyota', 1), ('ohmygoodness', 1)- I've never seen aVALUESclause like that, how would that even work?table(var1,var2) VALUES (row1_1,row1_2), (row2_1,row2_2) Try it, it works