插入 ... SELECT PHP

INSERT ... SELECT PHP

我需要一双新眼睛来帮助我发现我的代码有什么问题。

 <?php
ob_start();
session_start();

$sql = "INSERT INTO pets (owner_service, Gender, Age, Size, Location, idealLocation, Service, memberID) 
        SELECT ('{$_POST['owner_service']}', '{$_POST['gender']}', '{$_POST['age']}', '{$_POST['size']}', '$locationCommaString', '{$_POST['ideal_location']}', '{$_POST['service']}', memberID FROM members WHERE username = '{$_POST['username']}')";


        if($conn->query($sql) === TRUE) {
        echo "successful";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

?>

错误说:

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 'FROM members WHERE username = '')' at line 2

MySQL 版本为 5.5.41

认为一定是:

$sql = "INSERT INTO pets (owner_service, Gender, Age, Size, Location, idealLocation, Service, memberID) 
        SELECT '{$_POST['owner_service']}', '{$_POST['gender']}', '{$_POST['age']}', '{$_POST['size']}', '$locationCommaString', '{$_POST['ideal_location']}', '{$_POST['service']}', memberID FROM members WHERE username = '{$_POST['username']}'";

您必须删除 SELECT 之后和语句末尾的括号。 您还必须了解准备好的语句。