文库网站PHP开发会员充值功能代码

 文档付费没有金币的轻快需要提示用户充值金币,完成后才能付金币下载文档

会员充值功能代码:


<?php

// 连接数据库
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}


// 获取表单数据
$member_id = $_POST['member_id']; // 会员ID
$amount = $_POST['amount']; // 充值金额

// 插入数据到数据库

$sql = "INSERT INTO member_recharge (member_id, amount) VALUES ('$member_id', '$amount')";

if ($conn->query($sql) === TRUE) {
    echo "充值成功!";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}


// 关闭数据库连接
$conn->close();
?>