为什么我的SQL PHP代码不起作用?

时间:2016-02-05 06:28:47

标签: php

我的PHP代码无效。

{{1}}

我主要得到意外的T_STRING相关错误。我知道它尖叫业余时间,但任何帮助将是嗯......乐于助人

3 个答案:

答案 0 :(得分: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?

答案 1 :(得分:0)

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

//并且在每个sql Query之后使用php die()来获得重新处理

答案 2 :(得分: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);
}