2014-07-04 59 views
-1

我有一個插入到數據庫和我插入的文本有<a href=""></a>標籤。數據庫varchar列上的超鏈接

mysql_query("INSERT INTO `pm`(`message`) VALUES('You have been Invited to the team hello Click <a href="http://localhost:8080/competitive/accept.php">here</a> to accept.')"); 

從柱回聲的結果是這樣的:

You have been Invited to the team hello Click href="http://localhost:8080/competitive/accept.php">here to accept. 

而且我希望它看起來像這樣:

You have been Invited to the team hello Click here/*this is an link*/ to accept. 

如何使其正常?

編輯:

全碼:http://jsfiddle.net/Mvpy8/ PS:不要運行剛纔看到的代碼。

+0

我很驚訝的是,INSERT在所有工作,因爲你必須逃脫'‘'字符爲'\’'。 –

+0

將''。team_name.''改爲'「。$ team_name。」'並且將'here'改爲'accept',以'here接受',如何輸出文本? ''。*** [提示] ***在dbl引號前添加反斜槓 –

+0

是的,我使用的是echo – Matthew

回答

0

這應該按預期工作:

mysql_query("INSERT INTO `pm` (`message`) VALUES ('You have been Invited to the team ".$team_name." Click <a href=\"http://localhost:8080/competitive/accept.php\">here</a> to accept.')"); 
$result = mysql_query("SELECT `message` FROM `pm` LIMIT 1"); 
if($row = mysql_fetch_row($result)) { 
    echo $row[0]; 
} 

但你使用mysqli爲mysql。

如果這不起作用,請發佈您遇到問題的確切代碼!

+0

完整的代碼在這裏:http://jsfiddle.net/Mvpy8/不運行它,它只是爲你看 – Matthew

+0

如果使用單引號(''')封裝字符串,你不必逃避雙引號(''')。但問題似乎在於你的輸出。輸出行的代碼在哪裏? –

+0

輸出:http://jsfiddle.net/pzXS4/ – Matthew

0

問題是與您的使用「和」試試這個。

mysql_query("INSERT INTO `pm`(`message`) VALUES('You have been Invited to the team ".$team_name." Click <a href='http://localhost:8080/competitive/accept.php'>here</a> to accept.')"); 
+0

現在看起來像這樣'你已被邀請加入團隊hello點擊href = \'http:// localhost:8080/competitive/accept.php \'>在這裏接受。 – Matthew