php$link = mysqli_connectlocalhost admin admin data_breach;if !$link die连接失败 mysqli_connect_error;if isset$_POSTinput1 $value1 = intvalmysqli_real_escape_string$link $_POSTinput1; $value2
<?php
$link = mysqli_connect("localhost", "admin", "admin", "data_breach");
if (!$link) {
die("连接失败: " . mysqli_connect_error());
}
if (isset($_POST['input1'])) {
$value1 = intval(mysqli_real_escape_string($link, $_POST['input1']));
$value2 = mysqli_real_escape_string($link, $_POST['input2']);
$value3 = intval(mysqli_real_escape_string($link, $_POST['input3']));
$value4 = intval(mysqli_real_escape_string($link, $_POST['input4']));
//确保所有POST值都被转义以避免SQL注入攻击
mysqli_autocommit($link, FALSE); //关闭自动提交功能
$insert_query = "INSERT INTO amount_of_data_leaked(S_num, Entity, Year, Records) VALUES ('$value1','$value2','$value3','$value4')";
$result = mysqli_query($link, $insert_query);
$query = "SELECT * FROM amount_of_data_leaked ORDER BY S_num DESC LIMIT 1";
$query_result = mysqli_query($link, $query);
$query_data = "";
$row = mysqli_fetch_assoc($query_result);
$query_data .= "S_num: " . $row['S_num'] . ", Entity: " . $row['Entity'] . ", Year: " . $row['Year'] . ", Records: " . $row['Records'] . "\n";
mysqli_commit($link); //提交事务
if ($result) {
echo "<script>alert('成功');window.location.href='increase-table1.php';</script>"; //弹窗显示增添完成和查询结果,重新载入页面
mysqli_close($link);
} else {
mysqli_rollback($link); //回滚事务
mysqli_close($link);
echo 'false';
echo gettype($value1);
echo $value1;
}
} else {
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>增添数据</title>
</head>
<body background="../../images/DNA1.jpg">
<style>
.aa {
font-family: 楷体;
font-size: 2.5rem;
position: absolute;
top: 50px;
left: 250px;
background: transparent;
text-shadow: 0 0 4px rgb(155, 116, 116),
0 0 4px rgb(155, 116, 116),
0 0 4px rgb(155, 116, 116);
}
<pre><code> .ab {
font-family: 楷体;
font-size: 2.5rem;
position: absolute;
top: 50px;
left: 250px;
background: transparent;
text-shadow: 0 0 4px rgb(155, 116, 116),
0 0 4px rgb(155, 116, 116),
0 0 4px rgb(155, 116, 116);
}
.zong{
display:flex;
width:100%;
height:500px;
}
.ac {
display: flex;
flex-direction: row;
width: 450px;
height: 500px;
margin-top: 100px;
margin-left: 100px;
border: 3px solid rgb(149, 108, 108);
border-radius: 50px;
background-color: rgb(211, 208, 206);
justify-content: center;
align-items: center;
}
.ad {
width: 700px;
height: 500px;
margin-top: 100px;
margin-left: 50px;
border: 3px solid rgb(149, 108, 108);
border-radius: 50px;
background-color: rgb(211, 208, 206);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.abc {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 1.5rem;
font-family: 楷体;
margin-top: 5px;
}
.query-menu {
width: 400px;
height: 40px;
margin-bottom: 25px;
margin-left: 30px;
align-self: flex-start;
}
.modify-data input {
width: 400px;
height: 40px;
margin-bottom: 25px;
margin-left: 30px;
}
.normal-button {
width: 200px;
height: 50px;
border-radius: 30px;
background-color: rgb(97, 151, 97);
text-align: center;
margin-top: 25px;
margin-left: 30px;
}
</style>
<div class="zong">
<div class="aa">添加数据</div>
<div class="ac">
<div class="abc">
<form action="increase-table1.php" method="post" id="increase-num-form">
序号:<input type="text" name="input1" placeholder="请输入内容..." style="width:400px;height:30px;margin-bottom: 25px"></br>
实体名称:<input type="text" name="input2" placeholder="请输入内容..." style="width:400px;height:30px;margin-bottom: 25px"></br>
泄露时间:<input type="text" name="input3" placeholder="请输入内容..." style="width:400px;height:30px;margin-bottom: 25px"></br>
泄漏量: <input type="text" name="input4" placeholder="请输入内容..." style="width:400px;height:30px;margin-bottom: 25px"></br>
<button type="submit" class="modify-button" style="width:150px;height:50px;border-radius: 30px;background-color: rgb(97, 151, 97);text-align: center;margin-top: 30px;">提交</button>
<button type="button" onclick="window.location.href = '../index.php'" style="width:150px;height:50px;border-radius: 30px;background-color: rgb(97, 151, 97);text-align: center;margin-top: 5px;">返回上一个页面</button>
</form>
</div>
</div>
<div class="ad">
<?php
// 获取表中数据 这里是自动提交
$select_query = "SELECT * FROM amount_of_data_leaked order by S_num desc limit 10";
$select_result = mysqli_query($link, $select_query);
$data = array();
while ($row = mysqli_fetch_assoc($select_result)) {
$data[] = $row;
}
echo '<table>';
// 输出表头
echo '<tr>';
foreach ($data[0] as $key => $value) {
echo '<th>' . $key . '</th>';
}
echo '</tr>';
// 输出数据行
foreach ($data as $row) {
echo '<tr>';
foreach ($row as $value) {
echo '<td>' . $value . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
</div>
</div>
</code></pre>
</body>
</html
原文地址: http://www.cveoy.top/t/topic/g6px 著作权归作者所有。请勿转载和采集!