MySQLへの接続が多すぎてつながらないことがあるので、
textsqlに変更してみました。
こちらもソースの著作権は放棄します。
※textsql.phpは含めていません。お手数ですが本家からダウンロードして、
同じ階層に置いてください。 br>
list.text
※二行目の1は消さないように。
また、このファイルは書き込み権限が必要です。
id,msg 1
edit.php
<?php require_once 'textsql.php'; $db = new CTextDB('list.txt'); switch ($_POST["mode"]){ case "ins": $data = array(); $data["msg"] = $_POST["msg"]; $db->insert( $data); break; case "del"; $del_condition = '$id == "' . $_POST["id"] . '"'; $db->delete( $del_condition); break; } header("Location: index.php"); ?>
index.php
<?php require_once 'textsql.php'; ?> <html> <head> <title>TODO LIST</title> </head> <body> <hr> <?php $db = new CTextDB('list.txt'); $rs = $db->select( null, "id"); $max_count = count($rs); echo "<table border='0'> <tr><td>内容</td><td></td></tr>"; for ($i = 0; $i < $max_count; $i++) { $item = $rs[$i]; echo "<form action='edit.php' method='POST'> <tr> <td>" . $item["msg"] . "</td> <td><input type='submit' value='削除'> <input type='hidden' value='del' name='mode'> <input type='hidden' value='" . $item["id"] . "' name='id'> </td> </tr> </form>"; } print "</table>"; ?> <form action='edit.php' method='POST'> <input type='text' name='msg' size='50'> <input type='submit' value='登録'> <input type='hidden' value='ins' name='mode'> </form> </body> </html>