0

The result of the block of code below is always "d=0".I dont understand why?

 if (!empty($_POST["transactionid"])) {

     $sql_set = "SET timestamp = '$timestamp',";
     $sql = "INSERT INTO phpclassifieds_payments
                $sql_set
                txnid = '$trnxid',
                adid  = '$adid',
                adtype = 'A',
                amountpaid ='$amount_paid'";

     $tx = mysql_query($sql);
     if ($tx) {
         $d = 1;
     } else {
         $d = 0;
     }
 }
user2226755
  • 12,494
  • 5
  • 50
  • 73
rdkrosan
  • 111
  • 1
  • 7

2 Answers2

0

See : MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET

Are you sure that your DBMS allow the INSERT INTO ... SET syntax ?

Maybe change it to :

INSERT INTO phpclassifieds_payments VALUES ('val 1', 'val 2', ...);

Try to debug it with :

$d = 0;
die('error sql : ' . mysql_error());

If mysql_error, it doesn't return any value try echo $sql; to see your sql query.

Community
  • 1
  • 1
user2226755
  • 12,494
  • 5
  • 50
  • 73
  • Their DBMS, as stated, is MySQL, which clearly allows for both those. – Hanky Panky Jul 28 '14 at 07:53
  • I am using this block of code in making REST API. I have to pass data in json(one of which is transactionid) and see its output. I am using Advanced Rest CLient Apllication and Postman to do so. How can i check for mysql_error()?? – rdkrosan Jul 28 '14 at 07:55
0

You must check have any bugs in your queries by using

echo "<pre>".mysql_error()."</pre>"

It'll returns the mysql error information of query just before processed.

You must also ensure that their is a space between your table name and SET statement,

just rewrite $sql_set = " SET timestamp = '$timestamp', ";

Otherwise your joined query string is

INSERT INTO phpclassifieds_paymentsSET timestamp = '$timestamp',
                txnid = '$trnxid',
                adid  = '$adid',
                adtype = 'A',
                amountpaid ='$amount_paid'