2017-07-07 34 views
0

我剛剛創建了一個.php文件,不幸的是我的sql查詢不能在我的虛擬主機上運行,​​但.php文件運行得很完美。所以問題是,我的SQL查詢不能被執行php - 爲什麼我的查詢不工作?

它說:

Post Gagal or Post failed (in english)

你能告訴我爲什麼有一個SQL錯誤,以及如何解決這個錯誤

this my php code

     date_default_timezone_set("Asia/Bangkok"); 
      ob_start(); 
      session_start(); 
      require 'connection.php'; 

      // if session is not set this will redirect to login page 
      if(!isset($_SESSION['user'])) { 
       header("Location: loginpanel.php"); 
       exit; 
      } 
      // select loggedin users detail 
      $res=mysqli_query($conn,"SELECT * FROM akun_admin WHERE idadmin=".$_SESSION['user']); 
      $userRow=mysqli_fetch_array($res); 

      if (isset($_POST['btn-post'])) { 
       $error = false; 
       // clean user inputs to prevent sql injections 
       $jd = trim($_POST['jd']); 
       $jd = strip_tags($jd); 

       $sa = trim($_POST['sa']); 
       $sa = strip_tags($sa); 

       $note = trim($_POST['note']); 
       $note = strip_tags($note); 

       $genre = trim($_POST['genre']); 
       $genre = strip_tags($genre); 

       $ps = trim($_POST['ps']); 
       $ps = strip_tags($ps); 

       $ep14 = trim($_POST['1Link480p']); 
       $ep17 = trim($_POST['1Link720p']); 
       $ep1 = trim($ep14.'-'.$ep17); 
       $ep1 = strip_tags($ep1); 

       $ep24 = trim($_POST['2Link480p']); 
       $ep27 = trim($_POST['2Link720p']); 
       $ep2 = trim($ep24.'-'.$ep27); 
       $ep2 = strip_tags($ep2); 

       $ep34 = trim($_POST['3Link480p']); 
       $ep37 = trim($_POST['3Link720p']); 
       $ep3 = trim($ep34.'-'.$ep37); 
       $ep3 = strip_tags($ep3); 

       $ep44 = trim($_POST['4Link480p']); 
       $ep47 = trim($_POST['4Link720p']); 
       $ep4 = trim($ep44.'-'.$ep47); 
       $ep4 = strip_tags($ep4); 

       $ep54 = trim($_POST['5Link480p']); 
       $ep57 = trim($_POST['5Link720p']); 
       $ep5 = trim($ep54.'-'.$ep57); 
       $ep5 = strip_tags($ep5); 

       $ep64 = trim($_POST['6Link480p']); 
       $ep67 = trim($_POST['6Link720p']); 
       $ep6 = trim($ep64.'-'.$ep67); 
       $ep6 = strip_tags($ep6); 

       $ep74 = trim($_POST['7Link480p']); 
       $ep77 = trim($_POST['7Link720p']); 
       $ep7 = trim($ep74.'-'.$ep77); 
       $ep7 = strip_tags($ep7); 

       $ep84 = trim($_POST['8Link480p']); 
       $ep87 = trim($_POST['8Link720p']); 
       $ep8 = trim($ep84.'-'.$ep87); 
       $ep8 = strip_tags($ep8); 

       $ep94 = trim($_POST['9Link480p']); 
       $ep97 = trim($_POST['9Link720p']); 
       $ep9 = trim($ep94.'-'.$ep97); 
       $ep9 = strip_tags($ep9); 

       $ep104 = trim($_POST['10Link480p']); 
       $ep107 = trim($_POST['10Link720p']); 
       $ep10 = trim($ep104.'-'.$ep107); 
       $ep10 = strip_tags($ep10); 

       $ep114 = trim($_POST['11Link480p']); 
       $ep117 = trim($_POST['11Link720p']); 
       $ep11 = trim($ep114.'-'.$ep117); 
       $ep11 = strip_tags($ep11); 

       $ep124 = trim($_POST['12Link480p']); 
       $ep127 = trim($_POST['12Link720p']); 
       $ep12 = trim($ep124.'-'.$ep127); 
       $ep12 = strip_tags($ep12); 

       $ep134 = trim($_POST['13Link480p']); 
       $ep137 = trim($_POST['13Link720p']); 
       $ep13 = trim($ep134.'-'.$ep137); 
       $ep13 = strip_tags($ep13); 

       $ep144 = trim($_POST['14Link480p']); 
       $ep147 = trim($_POST['14Link720p']); 
       $ep14 = trim($ep144.'-'.$ep147); 
       $ep14 = strip_tags($ep14); 

       $ep154 = trim($_POST['15Link480p']); 
       $ep157 = trim($_POST['15Link720p']); 
       $ep15 = trim($ep154.'-'.$ep157); 
       $ep15 = strip_tags($ep15); 

       $ep164 = trim($_POST['16Link480p']); 
       $ep167 = trim($_POST['16Link720p']); 
       $ep16 = trim($ep164.'-'.$ep167); 
       $ep16 = strip_tags($ep16); 

       $ep174 = trim($_POST['17Link480p']); 
       $ep177 = trim($_POST['17Link720p']); 
       $ep17 = trim($ep174.'-'.$ep177); 
       $ep17 = strip_tags($ep17); 

       $ep184 = trim($_POST['18Link480p']); 
       $ep187 = trim($_POST['18Link720p']); 
       $ep18 = trim($ep184.'-'.$ep187); 
       $ep18 = strip_tags($ep18); 

       $ep194 = trim($_POST['19Link480p']); 
       $ep197 = trim($_POST['19Link720p']); 
       $ep19 = trim($ep194.'-'.$ep197); 
       $ep19 = strip_tags($ep19); 

       $ep204 = trim($_POST['20Link480p']); 
       $ep207 = trim($_POST['20Link720p']); 
       $ep20 = trim($ep204.'-'.$ep207); 
       $ep20 = strip_tags($ep20); 

       $ep214 = trim($_POST['21Link480p']); 
       $ep217 = trim($_POST['21Link720p']); 
       $ep21 = trim($ep214.'-'.$ep217); 
       $ep21 = strip_tags($ep21); 

       $ep224 = trim($_POST['22Link480p']); 
       $ep227 = trim($_POST['22Link720p']); 
       $ep22 = trim($ep224.'-'.$ep227); 
       $ep22 = strip_tags($ep22); 

       $ep234 = trim($_POST['23Link480p']); 
       $ep237 = trim($_POST['23Link720p']); 
       $ep23 = trim($ep234.'-'.$ep237); 
       $ep23 = strip_tags($ep23); 

       $ep244 = trim($_POST['24Link480p']); 
       $ep247 = trim($_POST['24Link720p']); 
       $ep24 = trim($ep244.'-'.$ep247); 
       $ep24 = strip_tags($ep24); 

       $tp = date("Y-m-d"); 
       $wp = date("h:i:sa"); 

       $ap = $userRow['alias']; 

      function generateRandomString($length = 50) { 
       $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
       $charactersLength = strlen($characters); 
       $randomString = ''; 
       for ($i = 0; $i < $length; $i++) { 
        $randomString .= $characters[rand(0, $charactersLength - 1)]; 
       } 
       return $randomString; 
      } 
       $postID = generateRandomString(); 
       // if there's no error, continue to signup 
       if(!empty($jd)) { 
       $res = mysqli_query($conn,"INSERT INTO postperepisode1_12 (idpost, judulpost, tanggal, waktu, adminposting, genre, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1`, 18, 19, 20, 21, 22, 23, 24, note, sinopsis) VALUES ('$postID', '$jd', '$tp', '$wp', '$ap', '$genre', '$ep1', '$ep2', '$ep3', '$ep4', '$ep5', '$ep6', '$ep7', '$ep8', '$ep9', '$ep10', '$ep11', '$ep12', '$ep13', '$ep14', '$ep15', '$ep16', '$ep17', '$ep18', '$ep19', '$ep20', '$ep21', '$ep22', '$ep23', '$ep24', '$sa', '$note')"); 

       if ($res) { 
       $errTyp = "success"; 
       $errMSG = "Posting Berhasil"; 
       } else { 
       $errTyp = "danger"; 
       $errMSG = "Post Gagal"; 
       } 

       } 


      } 
      ?> 
+0

由於PHP代碼運行良好,因此可能是數據庫錯誤。把它放在你的else語句中來檢查'echo(「Error description:」。mysqli_error($ conn));' – dipoisola

+0

你確定列名是否正確? 16,1',18 –

+0

那個錯誤,我剛剛編輯爲'16,17,18',但仍然不工作 –

回答

0

是的,我明白了,但它是你的自定義錯誤,也許你可以打印你的sql並執行
mysql客戶端。您可以首先檢查mysqli_error($ conn)

+0

我會嘗試先生,謝謝您的建議 –

+0

謝謝,我編輯了它。事實證明,mysql行不能用數字1,2,3等來命名。它們仍然應該由文本'a1,a2,a3等'給出。感謝您的建議,修復它^ _ ^ –