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.
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.
Comments