0

i want to store the posted parameters to my function in an array, i am using slim 3

My question

  1. is the request->getparam('') how i should get the parameters posted ?

  2. should i bind them ? if so to what should i bind them since i am not using :Adminusera :Adminuserb :Adminuserc anywhere

  3. is there a way i could place for example this in my array value :Adminusera instead of $userA ?

my code:

//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); 
    }
}
Morteza Asadi
  • 1,819
  • 2
  • 22
  • 39
mirvatJ
  • 366
  • 1
  • 3
  • 15

1 Answers1

0

Turns out i don't need to use bindparam i could just do it like this

$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); 
    }
}

thus i need to send the post request to my function using x-www-form-urlencoded

mirvatJ
  • 366
  • 1
  • 3
  • 15