2014-05-23 35 views
0

下面的php代碼在本地計算機(WAMP服務器)上運行時工作正常。然而,當我在網上覆制我的代碼到我的網絡服務器,我收到一條警告消息複製到虛擬主機帳戶時,MySQL_REAL_ESCAPE_STRING方法在php中不起作用?

警告:mysql_real_escape_string():拒絕訪問用戶 「馬歇爾」 @「localhost」的(使用密碼:NO)在 /HOME2/marshell/public_html/livedeals.uni.me/php/logmein.php

問題出在mysql_real_escape_string()方法。當我忽略這種方法,它在網上託管帳戶上工作正常嗎?有什麼問題,爲什麼它在我的本地wamp服務器上正常工作,而不是我的實際Web託管帳戶?

<?php 

    header("Access-Control-Allow-Origin: *"); 

    $FullNameBusinessName_original = $_POST['fnameorbname']; 

    $con = mysqli_connect("localhost", "xyzusername", "xyzpassword", "xyzdatabasename", "3306"); 
    mysqli_select_db($con,"xyzdatabasename"); 

    $FullNameBusinessName=mysql_real_escape_string($FullNameBusinessName_original); 

    mysqli_query($con,"INSERT INTO registration (FullNameBusinessName) VALUES ('".trim($FullNameBusinessName)."') "); 

    mysqli_close($con); 

    ?> 
+1

因爲'mysql_'和'mysqli_'是不一樣的。此外,你應該真正使用參數化查詢,而不是通過字符串連接將值插入到零中。 – Amber

+0

您可以在下面找到解決方案 http://stackoverflow.com/a/8813341/2588790 – Feroza

回答

1

你可能想,因爲你正在使用的mysqli的功能性使用mysqli_real_escape_string,而不是mysql_real_escape_string

$FullNameBusinessName = mysqli_real_escape_string($con, $FullNameBusinessName_original); 

See documentation here for further information

0

您正在使用mysqli_*而不是mysql_*。試着用

$FullNameBusinessName = mysqli_real_escape_string($con,$FullNameBusinessName_original); 

對於文檔替換

$FullNameBusinessName = mysql_real_escape_string($FullNameBusinessName_original); 

: - http://de2.php.net/manual/en/mysqli.real-escape-string.php

相關問題