2010-12-10 56 views
0
if($_GET['action'] == "add"){ 
     if($_SERVER['REQUEST_METHOD'] == "POST"){ 
      if(empty($_POST['bugtitle']) || empty($_POST['bugdetails'])){ 
       echo 'One of the fields was empty! Go back and try again.<br/>'; 
      } 
      else 
      { 
       $query = "INSERT INTO bra 
          (
          bugtitle, 
          bugdetails, 
          status, 
          ip, 
         ) 
          VALUES 
          (
          '". mysql_real_escape_string($_POST['bugtitle']) ."', 
          '". mysql_real_escape_string($_POST['bugdetails']) ."', 
          '0', 
          '". $_SERVER['REMOTE_ADDR'] ."' 
         )"; 
       $mysqlquery = mysql_query($query); 

       if($mysqlquery){ 
        echo 'Bug reported.<br/>'; 
       } 
       else 
       { 
        echo 'Mysql query failed! Please contact the webmaster!<br/>'.mysql_error().'<br/>'.$query; 
       } 
      } 
     } 
     else 
     { 
      ?> 
      <form action="bra.php?action=add" method="post"> 
       Bug title: <input type="text" name="bugtitle"/><br/> 
       Details:<br/> 
       <textarea cols="50" rows="5" name="bugdetails"></textarea><br/> 
       By pressing &#39;submit&#39; you understand that you will not spam and your ip adress will be logged.<br/> 
       <input type="submit" value="submit"/> 
      </form> 
      <?php 
     } 
    } 

而這正是它返回:Mysql查詢錯誤:出了什麼問題?

MySQL查詢失敗!請聯繫網站管理員! 你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在''VALUES'附近使用正確的語法'(在第7行有'錯誤','其呼叫')INSERT INTO胸罩(bugtitle,bugdetails,status,ip,) VALUES( '有一個錯誤', '而其所謂的瑪雅', '0', '127.0.0.1')

有什麼不對這個查詢?!?

+0

錯誤說:「有你在附近的語法錯誤')VALUES(...'」有什麼不對您的查詢,有你的語法錯誤時,多餘的逗號,就在')VALUES(...'。之前,換句話說,錯誤消息告訴你到底查詢有什麼問題, – 2010-12-10 09:57:04

回答

1

ip後刪除逗號。

INSERT INTO bra 
(
    bugtitle, 
    bugdetails, 
    status, 
    ip 
) 
+0

AH我錯過了!謝謝;) – Thew 2010-12-10 09:57:22

1
INSERT INTO bra 
         (
         bugtitle, 
         bugdetails, 
         status, 
         ip, 
        ) 

後IP是一個逗號,你應該將其刪除

0

您已在values之前再放一個COMMA(,)。 檢查:。

$query = "INSERT INTO bra 
          (
          bugtitle, 
          bugdetails, 
          status, 
          ip 
         ) 
          VALUES 
          (
          '". mysql_real_escape_string($_POST['bugtitle']) ."', 
          '". mysql_real_escape_string($_POST['bugdetails']) ."', 
          '0', 
          '". $_SERVER['REMOTE_ADDR'] ."' 
         )";