PHP 通過設定表單元素name屬性產生數組

來源:互聯網
上載者:User

標籤:資料表   host   變數   submit   inpu   name   sele   單元素   引用   

<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>

 

PHP 通過設定表單元素name屬性產生數組

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.