2012-12-03 16 views
-2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
      <title>Aliens Abducted Me - Report an Abduction</title> 
     </head> 
     <body> 
     <h2>Aliens Abducted Me - Report an Abduction</h2> 

      <?php 
       $firstname = $_POST['firstname'] ; 
       $lastname= $_POST['lastname']; 
       $when_it_happened = $_POST['whenithappened']; 
       $how_long = $_POST['howlong']; 
       $how_many = $_POST['howmany']; 
       $alien_description = $_POST['howlook']; 
       $what_they_did = $_POST['whattheydid']; 
       $fang_spotted = $_POST['fangspotted']; 
       $email = $_POST['email']; 
       $other = $_POST['anythingelse']; 

       /* $to = "[email protected]"; 

       $subject = "Aliens Abducted Me - Abduction Report"; 
       $msg ="$name was abducted $when_it_happened and was gone for $how_long.\n" . 
        "Number of aliens: $how_many\n" . 
        "Alien description: $alien_description\n" . 
        "What they did: $what_they_did\n" . 
        "Fang spotted: $fang_spotted\n" . 
        "Other comments: $other"; 
       mail($to, $subject, $msg, 'From:' . $email); */ 


      $connect=mysqli_connect("localhost","gamenewton","random","aliensdata") or die('THE MYSQL CONNECTION FAILED TO CONNECT'); 
      $query="INSERT INTO alien_form "."(firstname,lastname,email,whenit,whattheydid,howlong,fang_spotted,anythingelse) ". 
       "VALUES('$firstname','$lastname','$email','$when_it_happened','$what_they_did,'$how_long','$fang_spotted','$other')" or die('Error in wirting query'); 

      $result= mysqli_query($connect, $query) or die('Error in contacting the database for query'); 

錯誤發生在這裏只是這條消息上一行mysqli_query()中的PHP與MYSQL錯誤?我已經指出了錯誤的地方有註釋

   mysqli_close($connect); 

      echo 'Thanks for submitting the form.<br />'; 
      echo 'You were abducted ' . $when_it_happened; 
      echo ' and were gone for ' . $how_long . '<br />'; 
      echo 'Number of aliens: ' . $how_many . '<br />'; 
      echo 'Describe them: ' . $alien_description . '<br />'; 
      echo 'The aliens did this: ' . $what_they_did . '<br />'; 
      echo 'Was Fang there? ' . $fang_spotted . '<br />'; 
      echo 'Other comments: ' . $other . '<br />'; 
      echo 'Your email address is ' . $email; 
     ?> 

我使用wampp處理PHP和得到這個錯誤,因爲我有添加die()以瞭解發生此錯誤的位置。

+5

我們只是希望[鮑比表(http://xkcd.com/327/)是不會被綁架。 –

+1

查看[mysqli](http://php.net/mysqli)的手冊:有很多變量可以告訴您有關錯誤狀態的詳細信息。看看他們,找出錯誤是什麼。 – Quentin

+0

如何把大括號{$ firstname}和做死(mysql_error()) – vodich

回答

3

在SQL插入你錯過了一個單引號後what_they_did

$query="INSERT INTO alien_form "."(...) ". 
    "VALUES(...,'$what_they_did,'$how_long',...)" 
+0

: - 感謝你的朋友你是對的我已經錯過了這個愚蠢的報價...我的代碼現在工作正常。 .. 非常感謝你 –

相關問題