在mysql中摆脱撇号?

时间:2013-02-16 17:58:32

标签: php html mysql

有人可以帮助,我有一个文本区域表单,用户可以输入内容并提交它,然后内容存储在mysql表中。

我遇到的问题是,每当用户键入撇号'这是插入/和我想摆脱/.

我的专栏是utf8_general_ci格式(长文)我甚至在这里使用了正确的格式吗?

这也是我的代码,也许我需要在mysql中放一些东西?

请有人告诉我哪里出错了谢谢你。

html表格:

<form action="includes/changebio.php" method="post" id="form1">         
 <textarea id="bio" style="width: 448px; 
    margin-top:3px;
    text-align:left;
    margin-left:-2px;
    height: 120px;
    resize: none; 
    border: hidden;" textarea name="bio" data-id="bio" maxlength="710"><?php echo htmlspecialchars($profile['bio']); ?></textarea>
<input type="image" src="assets/img/icons/save-edit.png"class="bio-submit" name="submit" value="submit" id="submit"/>
</form>

MySQL的:

<?php ob_start(); ?>
<?php
require_once("session.php"); 
require_once("functions.php");
require('_config/connection.php');
?>
<?php 
session_start();
include '_config/connection.php'; 
$bio = $_POST['bio'];
$result = mysql_query("SELECT bio FROM ptb_profiles WHERE id=".$_SESSION['user_id']."");
if(!$result) 
{ 
echo "The username you entered does not exist"; 
} 
else 
if($bio!= mysql_result($result, 0)) 
{ 
echo ""; 
    $sql=mysql_query("UPDATE ptb_profiles SET bio ='".mysql_real_escape_string($bio)."' WHERE id=".$_SESSION['user_id'].""); 
}
header("Location: {$_SERVER['HTTP_REFERER']}");
?>
<?php ob_end_flush() ?>

1 个答案:

答案 0 :(得分:1)

有两种可能的情况

  1. 你有魔术引号。 Turn them off.
  2. 在您的所有输入数据上运行某种 Sanitize Them All 功能。摆脱它。