您应该制作一个包含 3 列的数据库表(对于这个问题)。
我会给你制作所需表格的代码,只需将其复制并粘贴到 PHPmyAdmin 中:
Create Table donations(
company_id int,
user_id int,
donate_num int,
datetime DATETIME
)
然后使用该INSERT INTO
函数使用新的 mysqli 函数更新数据库(将服务器/用户名等替换为您的数据库详细信息):
$mysqli= new mysqli('SERVER','USERNAME','PASSWORD','DATABASE NAME')
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
function escapeStringSlash($value) {
global $mysqli;
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = $mysqli->real_escape_string($value);
}
return $value;
}
$coid=escapeStringSlash($row['companyid']);
$userid = escapeStringSlash($_SESSION['userid']);
$selectbox = escapeStringSlash($_POST['select']);
$date = new DateTime();
$currentTime = $date->format("Y-m-d H:i:s");
if($insertDonations=$mysqli->query("INSERT INTO donations(company_id,user_id,donate_num,datetime) VALUES(".$coid.",".$userid.",".$selectbox.",'".$currentTime."')"){
echo "Number of donations received";
}else{
echo "There was a problem inserting this.";
}
$mysqli->close();