MySQL INSERT query works in Phpmyadmin but not in PHP
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.
No comments:
Post a Comment