1

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??

3
  • 1
    What means but it dosent work? Commented Jan 28, 2016 at 10:05
  • Obviously a syntax error / typo. Didn't your IDE tell you? Commented Jan 28, 2016 at 10:06
  • hi Raptor , thanks for your comment, I use nortpad++ and it did not tell me any thing:( Commented Jan 28, 2016 at 10:12

3 Answers 3

3

Try this one instead :

$sql0 = "UPDATE tName SET colName=REPLACE(colName,'\"','')";

notice there is a back slash :)

Sign up to request clarification or add additional context in comments.

Comments

2

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);
}

2 Comments

Looks like we answered at the same time :)
and by the second! what a coincidence. here, have a cookie gives cookie
1

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,'"','')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.