PHP+MySQL数据库ID重新排序源码
时间:2021-07-01 10:21:17
帮助过:37人阅读
$localhost="localhost"
;
$root="root"
;
$password="123456"
;
$datebest="db_ku"
;
$conn=
mysqli_connect(
$localhost,
$root,
$password,
$datebest) or
die("数据库服务器连接错误".
mysqli_error(
$conn));
mysqli_select_db(
$conn,
$datebest) or
die("数据库访问错误".
mysqli_error(
$conn));
mysqli_query(
$conn,"set character set utf8"
);
mysqli_query(
$conn,"set names utf8"
);
function edit_id()
{
Global $conn;
$table_name=
$_POST[‘name‘
];
$sql="ALTER TABLE `".
$table_name."` DROP id"
;
$sql1="ALTER TABLE `".
$table_name."` ADD id MEDIUMINT(8) NOT NULL FIRST"
;
$sql2="ALTER TABLE `".
$table_name."` MODIFY COLUMN id MEDIUMINT(8) NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id)"
;
mysqli_query(
$conn,
$sql);
mysqli_query(
$conn,
$sql1);
mysqli_query(
$conn,
$sql2);
echo mysqli_error(
$conn);
echo "<script>alert(‘重置ID成功!‘);history.back();</script>"
;
exit;
}
if (
$_SERVER[‘REQUEST_METHOD‘] === ‘POST‘
) {
edit_id();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>重置ID</title>
</head>
<style type="text/css">
form{
margin:50px 30%
;
width:
400px;
}
div{
display:
inline;
}
label{
border:
1px solid;
background-color:
#4CAF50;
}
input{
width:
200px;
padding:
7px 0px;
}
button {
background-color:
#4CAF50;
}
</style>
<body>
<form action="<?php echo
$_SERVER[‘PHP_SELF‘]; ?>" method="post" enctype="multipart/form-data" autocomplete="off">
<div>
<label
for="name">表名:</label>
<input type="text" id="name" name="name" placeholder="输入数据库需要重置ID数据表名">
</div>
<div><button>提交</button></div>
</form>
</body>
</html>
二、展示
PHP+MySQL数据库ID重新排序源码
标签:incr cti Enctype line label null 成功 password name