2014-12-05 187 views
-3

我想設置一個mysql數據庫來捕獲來自html表單的信息,但是當我測試它時,會返回下面的錯誤。該文件與數據庫位於同一臺服務器上。我的php位於錯誤之下。爲什麼我收到這個錯誤?

警告:mysql_connect()[function.mysql-connect]:拒絕用戶訪問inmoti6_ted_seminar'@'localhost'(使用password:YES)在/home/westcl5/public_html/drjseminars.com/thankyou.php上線92 無法連接:拒絕訪問用戶inmoti6_ted_seminar'@「localhost」的(使用密碼:YES)

if($_POST) 
     { 
      $con = mysql_connect("localhost","inmoti6_ted_seminar","Polarbear5"); 

      if (!$con) 
      { 
      die('Could not connect: ' . mysql_error()); 
      } 

      mysql_select_db("inmoti6_westcl5_ted_sem", $con); 

      $users_firstName = $_POST['first_name']; 
      $users_lastName = $_POST['last_name']; 
      $users_street = $_POST['street']; 
      $users_street2 = $_POST['street2']; 
      $users_city = $_POST['city']; 
      $users_state = $_POST['state']; 
      $users_zip = $_POST['zip']; 
      $users_country = $_POST['country']; 
      $users_email = $_POST['email']; 
      $users_telephone = $_POST['telephone']; 
      $users_practice = $_POST['practice']; 

      $users_firstName = mysql_real_escape_string($users_firstName); 
      $users_lastName = mysql_real_escape_string($users_lastName); 
      $users_street = mysql_real_escape_string($users_street); 
      $users_street2 = mysql_real_escape_string($users_street2); 
      $users_city = mysql_real_escape_string($users_city); 
      $users_state = mysql_real_escape_string($users_state); 
      $users_zip = mysql_real_escape_string($users_zip); 
      $users_country = mysql_real_escape_string($users_country); 
      $users_email = mysql_real_escape_string($users_email); 
      $users_telephone = mysql_real_escape_string($users_telephone); 
      $users_practice = mysql_real_escape_string($users_practice); 

      $query = " 
      INSERT INTO `westcl5_ted_sem`.`ted_seminar` (`First Name`, `Last Name`, `E-mail`, `Phone #`, `Street Address`, `Street Address 2`, `City`, `State`, `Zip Code`, `Country`, `Practice`) VALUES ('$users_firstName', '$users_lastName', '$users_email', '$users_telephone', '$users_street', '$users_street2', '$users_city', '$users_state', '$users_zip', '$users_country', '$users_practice');"; 

      mysql_query($query); 

      mysql_close($con); 
     } 
+1

看來你的數據庫用戶沒有足夠的權限,給你的用戶所需的權限 – Adeel 2014-12-05 06:20:17

+1

而且還注意到,'mysql_ *'功能已被棄用。停止使用它們,因爲它不再安全。看看'PDO'或'MySQLi' :) – Darren 2014-12-05 06:23:12

回答

0

問題是與您的密碼這是不匹配的。嘗試defulat $ con = mysql_connect(「localhost」,'root','');而不是 $ con = mysql_connect(「localhost」,「inmoti6_ted_seminar」,「Polarbear5」);

雖然在XAMPP上工作,但我也收到了這個錯誤,但通過使用上面提到的那條線來解決我的問題。

0

您將需要授予inmoti6_ted_seminar用戶權限。以root身份登錄到mysql服務器並執行以下SQL,您當然可以設置他們擁有的權限,但我認爲您只需要INSERT

CREATE USER 'inmoti6_ted_seminar'@'localhost' IDENTIFIED BY 'Polarbear5'; 
GRANT INSERT ON inmoti6_westcl5_ted_sem.* TO 'inmoti6_ted_seminar'@'localhost';