MySQL INSERT query works in Phpmyadmin but not in PHP

user114671

Very strange. I can't see what's going wrong here. The connection to the MySQL database has been made but it won't INSERT from PHP. It's fine if I run the query in Phpmyadmin.

$rawquery = "
    INSERT INTO $log_table_name
        (ref, timestamp, txn_id, email, item_name, item_number, custom, mc_gross, mc_currency, paypal_message)
    VALUES
        (NULL, CURRENT_TIMESTAMP, '$txn_id', '$payer_email', '$item_name', '$item_number', '$custom', '$payment_amount', '$payment_currency', 'INVALID');
";
echo $rawquery;
$query = mysql_query($link, $rawquery) or die('Could not access table');

Produces:

INSERT INTO wp_ipn_log
    (ref, timestamp, txn_id, email, item_name, item_number, custom, mc_gross, mc_currency, paypal_message)
VALUES
    (NULL, CURRENT_TIMESTAMP, '', '', '', '', '', '', '', 'INVALID');Could not access table

I'm expecting the INVALID message, I just want it to be inserted into the database.

Is the problem the format of the query, or is there an issue with the database, or something else?

ADDITIONAL INFO (as requested by vinodadhikary):

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $link) or die ("Could not open db ".mysql_error());

This is working fine.

Sean

When trying to debug code, it is helpful to use mysql_error()/mysqli_error($link) in your die() rather than a generic string - die('Could not access table').

Also, the order of query/link in mysql/mysqli is not the same

mysql_query is mysql_query(query,link), so your code should be

$query = mysql_query($rawquery,$link) or die(mysql_error()); 

while mysqli_query is mysqli_query(link, query), so your code should be

$query = mysqli_query($link, $rawquery) or die(mysqli_error($link));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL query works in PHPMyAdmin but not PHP

From Dev

Mysql query works in Phpmyadmin but not works in PHP

From Dev

MySQL SELECT query works in PHPmyadmin, not in PHP

From Dev

mysql query works in phpmyadmin but errors in php

From Dev

Query works in phpmyadmin but not in PHP

From Dev

Insert query works on phpMyAdmin but not with Java

From Dev

PHP MYSQL query won't work in PHP but works in PHPMyAdmin

From Dev

mysql and php %like% query. Works in phpmyadmin but different results php

From Dev

MySQL UPDATE works in phpMyAdmin but not in PHP

From Dev

mysql query works in phpmyadmin but not in node.js

From Dev

MySQL Query Not Working Live But Works In PHPMyAdmin

From Dev

A query that uses variables works in PHPMyAdmin, but not in a PHP script

From Dev

SQL Query works in phpMyAdmin but not in php page

From Dev

A query that uses variables works in PHPMyAdmin, but not in a PHP script

From Dev

How can I get a mysql script that works in PHPmyadmin, to work in a PHP mysql query?

From Dev

PHP and MySQL french accent works in PHPMyAdmin but not in page

From Dev

php mysql (INSERT QUERY)

From Dev

Insert fails in phpMyAdmin, but works when using MySQL directly

From Dev

DB query from PHP gives no result but same query on phpMyAdmin works?

From Dev

query works in mysql terminal but not in php

From Dev

query works in mysql fails in php

From Dev

MySQL query runs ok in phpMyAdmin but hangs in PHP

From Dev

MySQL query working in PHPMyAdmin but not working in PHP

From Dev

MySQL query runs ok in phpMyAdmin but hangs in PHP

From Dev

MySQL INSERT query works but Data is not inserted

From Dev

mysql "between date" query works in phpmyadmin but returns nothing with PDO

From Dev

PHP MySQL Insert Into query not working

From Dev

insert php mysql query in hyperlink

From Dev

PHP mysql query insert where

Related Related

  1. 1

    MySQL query works in PHPMyAdmin but not PHP

  2. 2

    Mysql query works in Phpmyadmin but not works in PHP

  3. 3

    MySQL SELECT query works in PHPmyadmin, not in PHP

  4. 4

    mysql query works in phpmyadmin but errors in php

  5. 5

    Query works in phpmyadmin but not in PHP

  6. 6

    Insert query works on phpMyAdmin but not with Java

  7. 7

    PHP MYSQL query won't work in PHP but works in PHPMyAdmin

  8. 8

    mysql and php %like% query. Works in phpmyadmin but different results php

  9. 9

    MySQL UPDATE works in phpMyAdmin but not in PHP

  10. 10

    mysql query works in phpmyadmin but not in node.js

  11. 11

    MySQL Query Not Working Live But Works In PHPMyAdmin

  12. 12

    A query that uses variables works in PHPMyAdmin, but not in a PHP script

  13. 13

    SQL Query works in phpMyAdmin but not in php page

  14. 14

    A query that uses variables works in PHPMyAdmin, but not in a PHP script

  15. 15

    How can I get a mysql script that works in PHPmyadmin, to work in a PHP mysql query?

  16. 16

    PHP and MySQL french accent works in PHPMyAdmin but not in page

  17. 17

    php mysql (INSERT QUERY)

  18. 18

    Insert fails in phpMyAdmin, but works when using MySQL directly

  19. 19

    DB query from PHP gives no result but same query on phpMyAdmin works?

  20. 20

    query works in mysql terminal but not in php

  21. 21

    query works in mysql fails in php

  22. 22

    MySQL query runs ok in phpMyAdmin but hangs in PHP

  23. 23

    MySQL query working in PHPMyAdmin but not working in PHP

  24. 24

    MySQL query runs ok in phpMyAdmin but hangs in PHP

  25. 25

    MySQL INSERT query works but Data is not inserted

  26. 26

    mysql "between date" query works in phpmyadmin but returns nothing with PDO

  27. 27

    PHP MySQL Insert Into query not working

  28. 28

    insert php mysql query in hyperlink

  29. 29

    PHP mysql query insert where

HotTag

Archive