2016-02-05 46 views
-3

我的PHP代碼不起作用。爲什麼我的SQL PHP代碼不工作?

<?php 

include config.php; 

function addEntryInDB() { 
    $nxtaddr = $_POST ["txin_src"]; 
    $nxtkey  = $_POST ["txin_key"]; 
    $coinaddr = $_POST ["txout_src"]; 
    $burntxid = $_POST ["txid"]; 
    $coinkey = $_POST ["txout_src"]; 

    mysql_select_db($sql_db, $conn); 

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

    $sql = ("INSERT INTO X (
       NXTAddress, 
       NXTPubKey, 
       AltCoinAddr, 
       AltCoinKeys, 
       PoBTXID, 
       ContactDateCreated 
      ) 
      VALUES (
       '$nxtaddr', 
       '$nxtkey', 
       '$coinaddr', 
       '$coinkey', 
       '$burntxid', 
       NOW() 
      )") 

    mysql_query($sql, $conn); 
    mysql_close($conn); 
} 

我大部分意想不到的T_STRING相關的錯誤。我知道這尖叫業餘小時,但任何幫助將是嗯...有幫助

+3

缺少';查詢後'。 –

+1

缺少分號 – Ceeee

回答

0
<?php 

include config.php; 

function addEntryInDB() { 
    $nxtaddr = $_POST ["txin_src"]; 
    $nxtkey  = $_POST ["txin_key"]; 
    $coinaddr = $_POST ["txout_src"]; 
    $burntxid = $_POST ["txid"]; 
    $coinkey = $_POST ["txout_src"]; 

    mysql_select_db($sql_db, $conn); 

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

    $sql = ("INSERT INTO X (
       NXTAddress, 
       NXTPubKey, 
       AltCoinAddr, 
       AltCoinKeys, 
       PoBTXID, 
       ContactDateCreated 
      ) 
      VALUES (
       '$nxtaddr', 
       '$nxtkey', 
       '$coinaddr', 
       '$coinkey', 
       '$burntxid', 
       NOW() 
      )"); // here you missing semicolon 

    mysql_query($sql, $conn); 
    mysql_close($conn); 
} 
0

你已經在這裏失去了分號:

$sql = ("INSERT INTO X (
      NXTAddress, 
      NXTPubKey, 
      AltCoinAddr, 
      AltCoinKeys, 
      PoBTXID, 
      ContactDateCreated 
     ) 
     VALUES (
      '$nxtaddr', 
      '$nxtkey', 
      '$coinaddr', 
      '$coinkey', 
      '$burntxid', 
      NOW() 
     )"); //here you missed ; 

而且你的代碼很容易受到SQL注入這是一個真正的問題。閱讀和你的未來將被保存How can I prevent SQL injection in PHP?

0
$sql = ("INSERT INTO X (
        NXTAddress, 
        NXTPubKey, 
        AltCoinAddr, 
        AltCoinKeys, 
        PoBTXID, 
        ContactDateCreated 
       ) 
       VALUES (
        '$nxtaddr', 
        '$nxtkey', 
        '$coinaddr', 
        '$coinkey', 
        '$burntxid', 
        NOW() 
       )"); // you forget (;) hear 

//並有很好的實踐中使用PHP模具()每一個SQL查詢後得到重新處理