码迷,mamicode.com
首页 > 数据库 > 详细

PHP+MySQL数据库ID重新排序源码

时间:2020-07-02 09:34:53      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:incr   cti   Enctype   line   label   null   成功   password   name   

一、参考源码

<?php 

$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   

原文地址:https://www.cnblogs.com/wlei5206/p/13222825.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!