Reputation: 510
This question is a bit basic and have been covered many times but I'm not sure why my code doesn't do anything. it doesn't update string at all.
this is my code:
$fineImage = "users_fav/".$_GET['id']."/$newname";
$icon = "<img src='images/icon.png' height='70' width='70' />";
$sql = "UPDATE $lchat SET user_message = replace(user_message, '$icon', '$fineImage')";
$query = mysqli_query($db_conx, $sql);
the problem is that if I change the '$icon', '$fineImage'
to something like 'david', 'mark'
. it works fine and it will replace the david with mark...!
so why doesn't it work the way i do it?
Upvotes: 0
Views: 73
Reputation: 108841
It's likely that your call to MySQL's REPLACE(input, before, after)
is failing to find before
in its input
, so is returning input
unmodified.
Why could this be? Several reasons:
user_message
doesn't contain what you think it contains. For example, are the <
and >
tags entitized (that is, coded with <
and the like)?<img..>
tag with your $fine_image. Is $fineimage
also an <img ...>
tag? before
parameter contains embedded single quote characters. That could conspire to make your SQL string invalid.Upvotes: 2
Reputation: 703
Try this:-
$sql = "UPDATE {$lchat} SET `user_message` = replace(`user_message`, '{$icon}', '{$fineImage}')";
Make sure you have $lchat, $icon, $fineImage defined. :)
Upvotes: 0