1
I have the following parameter in my query UPDATE.
$consulta->bindValue(':foto', $foto, PDO::PARAM_STR);
What I would like to do is the following: If the variable $foto
come blank, how could I pass the same value I have in the database?
I ask this because as the variable is coming blank it is doing the update in the field with no value.
Check whether
$foto
is empty, if you are not pass, do so:if (!empty($foto)) { $consulta->bindValue(':foto', $foto, PDO::PARAM_STR); } else { // $foto está vazio }
– stderr
if you do not use the error parameter pq it is in the update clause
– William
could make a select, but I believe there is another way to pass the same value of the field without needing to recover before.
– William
Here’s what I do: when loading the data for change, create a field
hidden
with the nameoldfoto
when you receive the information for change make a simpleif
. If photo has nothing pass again to oldphoto. Just one point, paste your html on the screen!– novic
Virgilio Novic, I have already thought about this tbm, but I don’t like to use the field hiden much because it can open security breach in the application, in case the user gives an F12 just fill the field.
– William
Can’t this parameter be optional? Have you tried using
COALESCE
to indicate an alternative value? I don’t know if this is your case, but here has an example that can be adaptable.– stderr
stderr, PERFECT! I had forgotten about Coalesce, I did it this way and it worked out! photo=COALESCE(:photo, photo)
– William
@William If possible post a reply and mark it as resolved!
– stderr