-3

My PHP code is not working.

<?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);
}

I am mostly getting unexpected T_STRING related errors. I know it screams amateur hour but any help would be umm... helpful

John Adams
  • 19
  • 1

3 Answers3

0

you have missing semi colon here:

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

Also your code is prone to SQL injection which is a real problem. Read this and your future will be saved How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Ceeee
  • 1,392
  • 2
  • 15
  • 32
0
$sql = ("INSERT INTO X (
                    NXTAddress,
                    NXTPubKey,
                    AltCoinAddr,
                    AltCoinKeys,
                    PoBTXID,
                    ContactDateCreated
                )
                VALUES (
                    '$nxtaddr',
                    '$nxtkey',
                    '$coinaddr',
                    '$coinkey',
                    '$burntxid',
                    NOW()
                )"); // you forget (;) hear

//and for good practice use php die() after every sql Query to get reprocess

Amit Rajput
  • 2,061
  • 1
  • 9
  • 27
Nikunj
  • 86
  • 11
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);
}
sagar chopada
  • 332
  • 1
  • 11