Reputation: 53
I need to eliminate the character (") from a column in my database. I can do in mysql command line by the following command:
mysql> UPDATE tName SET colName=REPLACE(colName, '"','');
and it works perfectly. Since i need run in php, i have used the following syntax in php but it dosent work :
$sql0 = "UPDATE tName SET colName=REPLACE(colName,'"','')";
if (mysqli_query($conn, $sql0)) {
$result0 = "Unwanted Character is removed ";
} else {
$result0 = "Error Filtering is Failed: " . $sql . "<br>" . mysqli_error($conn);
}
any Idea??
Upvotes: 1
Views: 406
Reputation: 16117
You can use quotes in REPLACE function as:
$one = '"';
$sql0 = "UPDATE tName SET colName = REPLACE(colName,'$one','')";
If you echo $sql0
result is:
UPDATE tName SET colName = REPLACE(colName,'"','')
Upvotes: 1
Reputation: 1297
Try this one instead :
$sql0 = "UPDATE tName SET colName=REPLACE(colName,'\"','')";
notice there is a back slash :)
Upvotes: 3
Reputation: 3568
you have to escape double quotes inside double-quoted strings.
$sql0 = "UPDATE tName SET colName=REPLACE(colName,'\"','')";
if (mysqli_query($conn, $sql0)) {
$result0 = "Unwanted Character is removed ";
} else {
$result0 = "Error Filtering is Failed: " . $sql . "<br>" . mysqli_error($conn);
}
Upvotes: 2