user3371049 user3371049 - 5 months ago 7
MySQL Question

Issue with the character: ' (single quotation) when trying to save to mySql

When ever there is this character in a string I try to save: ' (single quotation) - it does not save. No error is generated. I need help to understand what is wrong. My character set must accomodate French characters. Otherwise everything works well.

<?php
header ('Content-type: text/html; charset=utf-8');

include_once('../../../init.php');

mysql_set_charset("utf8");

$articleid = $_POST['articleid'];
$contenu = $_POST['editabledata'];
$name = $_POST['name'];

mysql_query("
UPDATE al_articles SET $name='$contenu'
WHERE (ArticleID='$articleid')

") or die(mysql_error());

?>

Answer

Use addslashes

$articleid  = addslashes($_POST['articleid']);
$contenu  = addslashes($_POST['editabledata']);
$name  = addslashes($_POST['name']);
Comments