简体   繁体   English

插入 Select + 插入值()

[英]Insert Into Select + Insert Into Values()

        $query = "INSERT INTO tbl_event(mcode, packagetype)
                SELECT fcode, packagetype
                FROM tbl_family_accounts
                WHERE id = '$uID'
            ";

The columns mcode and packagetype is from the table tbl_family_accounts and i managed to successfully insert it. mcodepackagetype列来自表tbl_family_accounts ,我成功地插入了它。

  1. How can i improve my query to insert the event_title and event_descrip from <form> or my website.如何改进我的查询以从<form>或我的网站插入event_titleevent_descrip

You can put literals into the SELECT list.您可以将文字放入SELECT列表中。 In mysqli or PDO you would use placeholders for them, and bind them to the POST parameters.在 mysqli 或 PDO 中,您将为它们使用占位符,并将它们绑定到 POST 参数。

$query = "INSERT INTO tbl_event(mcode, packagetype, event_title, event_descrip)
    SELECT fcode, packagetype, ?, ?
    FROM tbl_family_accounts
    WHERE id = ?
";
$stmt = $conn->prepare($query);
$stmt->bind_param("sss", $_POST['title'], $_POST['description'], $uID);
$stmt->execute();

Replace the $_POST indexes with the actual names from your form.$_POST索引替换为表单中的实际名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM