Reputation: 821
Im doing a basic insert with pdo, and Im not having my sucess message when I submit my form.
But neither was having no error, so I use error_reporting(E_ALL);
in top of my code.
And Im getting one error now: : Only variables should be passed by reference in $insert->bindParam(9, convert_datetime($f['date']));
.
This error is quite enlightening, however, I do not understand why I'm having this error, because in other parts, for example to insert categories, I am using the function in my bindParam and it is working fine..
$insert = $pdo->prepare("INSERT INTO admins(name, email, pass, date) VALUES (?,?,?,?)");
$insert->bindParam(1, $f['name']);
$insert->bindParam(2, $f['email']);
$insert->bindParam(3, $f['pass']);
$insert->bindParam(4, convert_datetime($f['date']));
$insert->execute();
if($i_a->rowCount() >=1){
echo '<div>Admin inserted with sucess</div>';
}
My function convert_datetime()
function convert_datetime($date_received){
$english = array("...");
$spanish = array("...");
$result_date = str_ireplace ($english , $spanish, $date_received);
$date_received = DateTime::createFromFormat('l, j F, Y', $result_date);
$date_received = $date_received->format('Y-m-d H:i:s');
return $date_received;
Upvotes: 1
Views: 81
Reputation: 821
Thanks for your help, I found my problem now.
It seems that the problem was not related to my function inside my bindParam method.
My admins table have an column "avatar" that is defined as not null (avatar varchar(255) NOT NULL,
),
and I was inserting my admin without select any avatar image.
So I just needed to change in my database my avatar definiton to avatar varchar(255) DEFAULT NULL,,
and everything is working fine now.
Thanks for your help!
Upvotes: 2
Reputation: 12039
Arguments except the first are passed by reference. This means they must be variables, and not strings. Try this
$date = convert_datetime($f['date']);
$insert->bindParam(4, $date);
Upvotes: 1