zoukankan      html  css  js  c++  java
  • PHP 通过设置表单元素name属性生成数组

    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    //使用自引用表单,$_SERVER['PHP_SELF']变量显示PHP文件自身文件名
    <?php
    //连接MySQL数据库
    $dbc=mysqli_connect('localhost','root','root','test_store') or die('Error conneting to MySQL server.');
    //判断表单是否提交过
    if(isset($_POST['submit'])){
        foreach($_POST['todelete'] as $delete_id){
    //
    $_POST['todelete']就是todelete[]数组,被选中的复选框的值都会存在这个数组里面 $query="delete from email_list where id=$delete_id"; mysqli_query($dbc,$query) or die('error delete data.'); } echo "email is removed.<br />"; } //查询email_list数据表 $query="select * from email_list"; $result=mysqli_query($dbc,$query) or die('error select database.'); //生成复选框 while($row=mysqli_fetch_array($result)){ //$result存储的是查询到的整张数据表;while每执行一次,$row数组中存储的是数据表的一行数据。 echo '<input type="checkbox" value="'.$row['id'].'" name="todelete[]" />'; //注意name属性中方括号 echo $row['email']; echo '<br />'; } //关闭与数据库的连接 mysqli_close($dbc); ?> <br /> <input type="submit" name="submit" value="submit"> </form>
  • 相关阅读:
    GridView 内部添加控件
    TreeList获取选中内容
    TreeList简介
    TreeList
    DEV—【GridControl 按钮列无法触发点击事件解决方案】
    dev 多行文本 MemoEdit
    DevExpress控件使用小结
    DEV常用设置
    DEV常用设置
    documentManager1注意事项
  • 原文地址:https://www.cnblogs.com/nb08611033/p/8379986.html
Copyright © 2011-2022 走看看