我想将发布的参数存储到数组中的函数中, 我正在使用slim 3
我的问题
是request->getparam('')
我应该如何获取参数
张贴?
我应该绑定它们吗?如果是这样,我应该约束他们,因为我
不在任何地方使用:Adminusera :Adminuserb :Adminuserc
我可以在我的数组值:Adminusera
而不是$userA
中放置一个方法吗?
我的代码:
//IS THIS HOW I GET THE POSTED PARAMETERS To My Function ?
$userA = $request->getParam('usera');
$userB = $request->getParam('userb');
$userC = $request->getParam('userc');
$sql = "SELECT *FROM admins";
try {
$db = new db();
$db = $db->connect();
$stmt = $db->prepare($sql);
$stmt->bindParam(':Adminusera', $userA);
$stmt->bindParam(':Adminuserb', $userB);
$stmt->bindParam(':Adminuserc', $userC);
$stmt->execute();
$admin = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
if(!empty($admin)){
$newUsers = array('a' => $userA, 'b' => $userB, 'c' => $userC);
print_r($newUsers);
}
}
答案 0 :(得分:0)
原来我不需要使用bindparam我可以像这样做
$userA = $request->getParam('usera');
$userB = $request->getParam('userb');
$userC = $request->getParam('userc');
$sql = "SELECT *FROM admins";
try {
$db = new db();
$db = $db->connect();
$stmt = $db->prepare($sql);
$stmt->execute();
$admin = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
if(!empty($admin)){
$newUsers = array('a' => $userA, 'b' => $userB, 'c' => $userC);
print_r($newUsers);
}
}
因此我需要使用x-www-form-urlencoded
将post请求发送到我的函数