嘿,我在数据库中插入一些数据时遇到问题:
define('SECURE', true);
include "storescripts/connect_to_mysql.php";
$txn_id = 123456789101234567;
$payer_email = "irgendwas@gmx.de";
$mc_gross = "amount";
$sql = "SELECT COUNT(*) AS count FROM `trans` WHERE `txn_id` = $txn_id";
$q = mysqli_query($mysqli, $sql);
$f = mysqli_fetch_array($q);
if($f['count'] > 0) {
echo "Transaction already processed";
} else {
$insert = mysqli_query($mysqli, "INSERT INTO trans (`txn_id`, `payer_email`,`mc_gross`)
VALUES ($txn_id,$payer_email,$mc_gross)");
if($insert = 1) {
echo "inserted";
} else {
echo "not inserted";
}
}
结果我得到:“插入”,但我的数据库中没有数据..任何人都可以帮助我吗?错误在哪里?
编辑:这是我的桌子:
define('SECURE', true);
require "connect_to_mysql.php";
$sqlCommand = "CREATE TABLE trans (
id int(11) NOT NULL auto_increment,
txn_id varchar(255) NOT NULL,
payer_email varchar(255) NOT NULL,
mc_gross int(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY (txn_id))";
if ($mysqli->query($sqlCommand)) {
echo "Your trans table has been created successfully!";
} else {
echo "CRITICAL ERROR;".$mysqli->error;
}