gpt4 book ai didi

php - 设置 php 变量 $userName = swift Encodable $_POST [‘userName’ ] 变量的正确语法或方法是什么?

转载 作者:行者123 更新时间:2023-11-29 17:41:57 39 4
gpt4 key购买 nike

到目前为止,下面显示的第一个 $sql = “INSERT INTO MySQLtable 语句将插入一个包含静态文本的新行 VALUES ('statictext', 'statictext') 。问题是将可编码变量 userName 设置为 php 变量 $userName 以插入带有变量 VALUES ('$userName ', '$userEmail')?尝试了多种变体,但到目前为止都插入空白列条目:

// This $sql will insert new row with static text entries:
$sql = "INSERT INTO `MySQLtable`(`userName`, `userEmail`) VALUES ('statictext', 'statictext')";

解决方案更新:将Swift JSONEncoder().encode(Post)发送到数据库服务器,当然首先需要解码Post来设置其内容php变量,这样下面就完成了Encodable- PHP 路径:

session_start();

$PostContents = json_decode(file_get_contents("php://input"), true);
$userName = $PostContents["userName"];
$userEmail = $PostContents["userEmail"];

$sql = "INSERT INTO `MySQLtable`(`userName`, `userEmail`) VALUES ('$userName', '$userEmail')";

最佳答案

您的帖子显示了这一行:

USERvalues(userName: "Arthur Dent", userEmail: "improbabilitydrive@gmail.com")

如果这是变量的实际名称,那么您应该按以下方式访问它们:

USERvalues['userName'] and USERvalues['userEmail']

但是由于我无法知道正在发生什么其他事情,所以这个建议可能没有帮助。

关于php - 设置 php 变量 $userName = swift Encodable $_POST [‘userName’ ] 变量的正确语法或方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49961230/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com