2013-02-16 148 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