2013-02-16 90 views
0

有人可以请帮忙,我有一个文本区域的形式,用户可以键入内容并提交它,然后内容被存储在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

您正在使用[an **过时的**数据库API](http://stackoverflow.com/q/12859942/19068)并应使用[现代替换](http://php.net/)手动/ EN/mysqlinfo.api.choosing.php)。 – Quentin 2013-02-16 18:00:49

回答

1

有2个可能的情况

  1. 您对魔术引号。 Turn them off.
  2. 某种消毒它们全部函数在所有输入数据上运行。摆脱它。
+0

如何关闭魔术引号? – 2013-02-16 19:12:06

+0

@JohnJames - 您在答案的链接的另一端阅读页面。 – Quentin 2013-02-17 10:44:11