2012-06-08 99 views
-3

我正在寫一個php代碼,用戶輸入各種細節,然後將它們提交到表單中。但是,當我提出它,我得到這個作爲一個錯誤:提交php表格

Warning: mysql_query() [function.mysql-query]: Access denied for user 'sifeiitd'@'localhost' (using password: NO) in /home/sifeiitd/public_html/wh.php on line 95

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/sifeiitd/public_html/wh.php on line 95

我的PHP代碼是

<?php 
       //include the connection file 

       require_once('functions/connection.php'); 
       require_once('functions/functions.php'); 

       $display_query = mysql_query("SELECT * FROM eportal"); 

        echo "<table id='pageTable'><thead><tr><th>Item code</th><th>Image</th><th>Description</th><th>Cost</th></tr></thead>"; 
        echo "<tbody>"; 
        while($row = mysql_fetch_array($display_query)){ 
         print "<tr><td>".$row['itemid']."</td><td>"."</td><td>".$row['description']."</td><td>"; 
         print "&#8377;".$row['cost']."</td></tr>"; 
        } 
        echo "</tbody>"; 
        echo "</table>"; 
        mysql_close($connection); 

      ?> 
      <?php 

      //save the data on the DB and send the email 

      //If the user has submitted the form 
      if($_POST['submit']){ 
       //protect the posted value then store them to variables 
       $name = protect($_POST['name']); 
       $email = protect($_POST['email']); 
       $contact=protect($_POST['contact']); 
       $itemid=protect($_POST['itemid']); 
       $itemquantity=protect($_POST['itemquantity']); 
       $ip = gethostbyname($_SERVER['REMOTE_ADDR']); 
       $message = protect($_POST['message']); 
       //Check if the username or password boxes were not filled in 
       if(!$name || !$email || !$contact || !$itemid){ 
        //if not display an error message 
        echo "<center>Fields marked with <strong>&#40; &#42; &#421</strong> are mandatory!</center>"; 
        }else{ 
        //if the were continue checking 
         $result = mysql_query("INSERT INTO `wh_order` (`name`, `email`, `contact`, `itemid`, `itemquantity`, `ip`,`message`) VALUES('".$name."','".$email."','".$contact."','".$itemid."','".$itemquantity."','".$ip."','".$message."')"); 
         //send the email with the order 
         if($result) 
          { 
           //send the email 

           $to = "[email protected]"; 
           $subject = "New order for Weaving Hope"; 

           //headers and subject 
           $headers = "MIME-Version: 1.0\r\n"; 
           $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
           $headers .= "From: ".$name." <".$email.">\r\n"; 

           $body = "New contact<br />"; 
           $body .= "Name: ".$name."<br />"; 
           $body .= "Email: ".$email."<br />"; 
           $body .= "Contact No.: ".$contact."<br />"; 
           $body .= "Item Id: ".$itemid."<br />"; 
           $body .= "Quantity: ".$itemquantity."<br />"; 
           $body .= "Comment: ".$message."<br />"; 
           $body .= "IP: ".$ip."<br />"; 

           mail($to, $subject, $body, $headers); 

           //ok message 

           echo "Your message has been sent"; 
          } 
         } 
        } 
      ?> 
+2

顯示'connection.php' – k102

+0

它聽起來好像這段代碼運行正常,但連接文件中有錯誤。數據庫名稱,路徑,用戶名或密碼不正確。 –

+1

您使用了錯誤的數據庫憑據。另外,「保護」在哪裏定義?這聽起來像是一些自己寫的反SQLi的東西。如果是這樣,**不要這樣做** - 至少應該使用'mysql_real_escape_string'。目前,首選(也是最安全的方法)是使用MySQLi或PDO的參數化查詢。 – Polynomial

回答

3

Access denied for user 'sifeiitd'@'localhost' (using password: NO)

看起來相當明確的錯誤給我。檢查您的mysql_connect()聲明,可能在connection.php

+0

我修正了錯誤。它現在接受所有的輸入。我也收到了郵件。但數據庫尚未更新。 – homer

+0

@PrateekSachan你不會發出'update'語句。你的意思是數據沒有插入到數據庫中?然後檢查(回顯)你的插入查詢。 – CodeCaster

+0

對不起,是的,雖然我收到帶有提交值的電子郵件,但數據並未插入數據庫中。 – homer