洪发

Generation

fix invalid codeSun, 05 Feb 2023

<body> <div class="tianjia"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <h2>批量添加用户</h2> <label for="start">起始用户名:</label> <input type="text" id="start" name="start" required> <br><br> <label for="end">结束用户名:</label> <input type="text" id="end" name="end" required> <br><br> <input type="submit" value="提交"> </form> </div> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { include 'mysqli1.php'; $start = $_POST['start']; $end = $_POST['end']; for ($i = $start; $i <= $end; $i++) { $username = $i; $sql = "INSERT INTO users (username) VALUES ('$username')"; if (mysqli_query($conn, $sql)) { echo "<script>alert('添加成功');</script>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } mysqli_close($conn); } ?> </body>

### 参考文献 - [图解:手把手教你用MySQLi实现数据库的增删改查操作](https://www.jianshu.com/p/7d0d6dde7a97) - [PHP 的增删改查 (CRUD) 操作](https://www.runoob.com/php/php-crud.html)

Questions about programming?Chat with your personal AI assistant