代码如下:
<?php
//数据库配置
$user = ‘xxxx3′; //用户名
$password = ’65xxx3’; //密码
$database = ‘yxxx; //表名
$sqlurl = ‘xxxxx0’; //地址
//创建数据库连接
$conn = new mysqli($sqlurl, $user, $password, $database);
//检查连接是否成功
if ($conn->connect_error) {
die(“数据库连接失败: ” . $conn->connect_error);
}
//查询操作
if (isset($_POST[‘query’])) {
$email = $_POST[’email’];
$query_sql = “SELECT user_id FROM wp_users WHERE user_email=’$email'”;
$query_result = $conn->query($query_sql);
if ($query_result->num_rows > 0) {
$row = $query_result->fetch_assoc();
$user_id = $row[‘user_id’];
$query_balance_sql = “SELECT meta_value FROM wp_usermeta WHERE user_id=’$user_id’ AND meta_key=’cao_balance'”;
$query_balance_result = $conn->query($query_balance_sql);
if ($query_balance_result->num_rows > 0) {
$balance_row = $query_balance_result->fetch_assoc();
$balance = $balance_row[‘meta_value’];
echo “<script>alert(‘当前次数为: $balance’)</script>”;
} else {
echo “<script>alert(‘未查询到次数’)</script>”;
}
} else {
echo “<script>alert(‘未查询到该邮箱对应的用户’)</script>”;
}
}
//修改操作
if (isset($_POST[‘modify’])) {
$email = $_POST[’email’];
$balance = $_POST[‘balance’];
$password = $_POST[‘password’];
//检查密码是否正确
if ($password !== ‘xxxxx’) {
echo “<script>alert(‘密码不正确’)</script>”;
} else {
//检查是否输入次数
if (!$balance) {
echo “<script>alert(‘请输入增加的次数’)</script>”;
} else {
$query_sql = “SELECT user_id FROM wp_users WHERE user_email=’$email'”;
$query_result = $conn->query($query_sql);
if ($query_result->num_rows > 0) {
$row = $query_result->fetch_assoc();
$user_id = $row[‘user_id’];
$update_sql = “UPDATE wp_usermeta SET meta_value=meta_value+’$balance’ WHERE user_id=’$user_id’ AND meta_key=’cao_balance'”;
if ($conn->query($update_sql) === TRUE) {
echo “<script>alert(‘次数更新成功,当前次数为: $balance’)</script>”;
} else {
echo “错误: ” . $conn->error;
}
} else {
echo “<script>alert(‘未查询到该邮箱对应的用户’)</script>”;
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>查询和修改操作</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
form {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type=text],
input[type=password] {
padding: 7px;
width: 70%;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<div class=”container”>
<h2>查询和修改操作</h2>
<form method=”post”>
<label for=”email”>邮箱</label>
<input type=”text” id=”email” name=”email” placeholder=”输入邮箱” required>
<label for=”balance”>增加的次数</label>
<input type=”text” id=”balance” name=”balance” placeholder=”输入增加的次数”>
<label for=”password”>密码</label>
<input type=”password” id=”password” name=”password” placeholder=”输入密码” required>
<input type=”submit” name=”query” value=”查询”>
<input type=”submit” name=”modify” value=”确定修改”>
</form>
</div>
</body>
</html>
暂无评论内容