PHP Problem updating text fields containing ' symbol
Posted: Mon Nov 01, 2004 3:26 pm
Hi,
I am encountering a problem updating a text field in a MySQL table via PHP.
If there is a single quotation mark ' anywhere in the contents of the field, it will not update. Remove the quotation marks, and it updates fine. Here is the script.
I'm lost. This only happens when I am using UPDATE. No problem with INSERT or when I preview the contents on my browser.
Any suggestions?
I am encountering a problem updating a text field in a MySQL table via PHP.
If there is a single quotation mark ' anywhere in the contents of the field, it will not update. Remove the quotation marks, and it updates fine. Here is the script.
Code: Select all
require("openfirstdb.php");
$sq = "SELECT *";
$sq.= " FROM author ";
$sq.= " WHERE AUTO_ID = 0";
$rs = mysql_db_query($DBname,$sq,$link);
while ($row=mysql_fetch_array($rs)){
if($row["pass"]==$pass){ //checks password
$sq2 = "UPDATE author set ";
$sq2.= " body = '$sbody' ,";
$sq2.= " contact = '$contact', ";
$sq2.= " news = '$snews' ";
$sq2.= " WHERE AUTO_ID = 0";
$result = mysql_db_query($DBname,$sq2,$link);
if ($result){
print("Contents successfully updated.");
}
else {
print ("Contents not successfully updated.");
}
}
}Any suggestions?