PHP PDO - Cannot pass parameter 2 by reference

Status
Not open for further replies.

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Hey guys,

So with PDO I'm having issues (again) And I'm logging an action. Code:
PHP:
$log = $db->prepare('INSERT INTO logs(user,type,extradata) VALUES(:n,:t,:e)');
 $log->bindParam(':n', $_SESSION['username'], PDO::PARAM_STR);
  $log->bindParam(':t', 'add_folder', PDO::PARAM_STR);
  $log->bindParam(':e', 'Added folder named: ' . $name, PDO::PARAM_STR);
P.S. : I'm not using backticks because Turkish keyboard don't have it.

So error is at
PHP:
  $log->bindParam(':t', 'add_folder', PDO::PARAM_STR);
and I don't know whats wrong?

Thanks.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
PHP:
$username = $_SESSION['username'];
$extradata = 'Added folder named: ' . $name;

$log = $db->prepare("INSERT INTO `logs` (`user`, `type`, `extradata`) VALUES (:n, 'add_folder', :e)");
$log->bindParam(':n', $username, PDO::PARAM_STR);
$log->bindParam(':e', $extradata, PDO::PARAM_STR);
You can't directly pass in an array or input field like you've done. For practice sake, I'd suggest you do it like this above.
 
  • Like
Reactions: Sly

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
PHP:
$username = $_SESSION['username'];
$extradata = 'Added folder named: ' . $name;

$log = $db->prepare("INSERT INTO `logs` (`user`, `type`, `extradata`) VALUES (:n, 'add_folder', :e)");
$log->bindParam(':n', $username, PDO::PARAM_STR);
$log->bindParam(':e', $extradata, PDO::PARAM_STR);
You can't directly pass in an array or input field like you've done. For practice sake, I'd suggest you do it like this above.
Worked like a charm, thanks pal!
 
Status
Not open for further replies.

Users who are viewing this thread

Top