todo.php
· 3.0 KiB · PHP
Raw
<?php
/*
* PHP/MySQL todo script
* by blha303 (b3@blha303.tk)
* Change $host, $user and $password to the mysql login info you want to use.
* Released under the WTF license.
*/
echo "<html>
<head><title>Things to do</title></head>
<body>
<h1>Things to do</h1>
<form name='things' method=POST action='todo.php'>
";
$host="localhost";
$user="things";
$password="PASSWORD";
$cxn = mysqli_connect($host,$user,$password);
if (!empty($_POST['checkbox'])) {
$sql1 = "UPDATE things.items set isVisible=0 where iditems=".$_POST['checkbox'];
$result = mysqli_query($cxn,$sql1);
if($result == false) { echo "error updating table"; }
}
if (!empty($_POST['retr'])) {
$sql2 = 'select iditems,content,isVisible from things.items where iditems='.$_POST['retr'];
$result = mysqli_query($cxn,$sql2);
if($result == false) { echo "error retrieving data. <a href='todo.php'>Refresh</a>"; }
else {
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Content</th><th>isVisible</th></tr>";
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
$row_array = mysqli_fetch_row($result);
echo "<tr>";
for($j = 0;$j < mysqli_num_fields($result);$j++)
{
echo " <td>".$row_array[$j]."</td>\n";
}
echo "</tr>";
}
echo "</table><a href='todo.php'>Back</a>";
}
}
if (!empty($_POST['newcontent'])) {
$sql3 = "INSERT INTO things.items (content, isVisible) VALUES ('".$_POST['newcontent']."', 1)";
$result = mysqli_query($cxn,$sql3);
if($result == false) { echo "Could not add new todo"; }
}
if (!empty($_POST['list'])) {
$sql4 = "SELECT * from things.items";
$result = mysqli_query($cxn,$sql4);
if($result == false) { echo "Could not list all items. <a href='todo.php'>Back</a>"; }
else {
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Content</th><th>isVisible</th></tr>";
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
$row_array = mysqli_fetch_row($result);
echo "<tr>";
for($j = 0;$j < mysqli_num_fields($result);$j++)
{
echo " <td>".$row_array[$j]."</td>\n";
}
echo "</tr>";
}
echo "</table><a href='todo.php'>Back</a>";
}
}
if (empty($_POST['retr'])) {
if (empty($_POST['list'])) {
$sql="select iditems,content from things.items where isVisible = 1;";
$result = mysqli_query($cxn,$sql);
if($result == false)
{
echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
}
else
{
/* Table that displays the results */
echo "<table>
";
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
echo " <tr>
";
$row_array = mysqli_fetch_row($result);
for($j = 1;$j < mysqli_num_fields($result);$j++)
{
echo " <td><input type='checkbox' name='checkbox' value='".$row_array[$j-1]."' onClick='things.submit()'>".$row_array[$j]."</td>\n";
}
}
echo "
</table>
Retrieve: <input type='text' name='retr' size=2><input type='submit' value=''><br>
New: <input type='text' name='newcontent'><input type='submit'><br>
<input type='submit' name='list' value='List'>
</body>
</html>";
} } }
?>
| 1 | <?php |
| 2 | /* |
| 3 | * PHP/MySQL todo script |
| 4 | * by blha303 (b3@blha303.tk) |
| 5 | * Change $host, $user and $password to the mysql login info you want to use. |
| 6 | * Released under the WTF license. |
| 7 | */ |
| 8 | echo "<html> |
| 9 | <head><title>Things to do</title></head> |
| 10 | <body> |
| 11 | <h1>Things to do</h1> |
| 12 | <form name='things' method=POST action='todo.php'> |
| 13 | "; |
| 14 | $host="localhost"; |
| 15 | $user="things"; |
| 16 | $password="PASSWORD"; |
| 17 | $cxn = mysqli_connect($host,$user,$password); |
| 18 | if (!empty($_POST['checkbox'])) { |
| 19 | $sql1 = "UPDATE things.items set isVisible=0 where iditems=".$_POST['checkbox']; |
| 20 | $result = mysqli_query($cxn,$sql1); |
| 21 | if($result == false) { echo "error updating table"; } |
| 22 | } |
| 23 | if (!empty($_POST['retr'])) { |
| 24 | $sql2 = 'select iditems,content,isVisible from things.items where iditems='.$_POST['retr']; |
| 25 | $result = mysqli_query($cxn,$sql2); |
| 26 | if($result == false) { echo "error retrieving data. <a href='todo.php'>Refresh</a>"; } |
| 27 | else { |
| 28 | echo "<table border='1'>"; |
| 29 | echo "<tr><th>ID</th><th>Content</th><th>isVisible</th></tr>"; |
| 30 | for($i = 0; $i < mysqli_num_rows($result); $i++) |
| 31 | { |
| 32 | $row_array = mysqli_fetch_row($result); |
| 33 | echo "<tr>"; |
| 34 | for($j = 0;$j < mysqli_num_fields($result);$j++) |
| 35 | { |
| 36 | echo " <td>".$row_array[$j]."</td>\n"; |
| 37 | } |
| 38 | echo "</tr>"; |
| 39 | } |
| 40 | echo "</table><a href='todo.php'>Back</a>"; |
| 41 | } |
| 42 | } |
| 43 | if (!empty($_POST['newcontent'])) { |
| 44 | $sql3 = "INSERT INTO things.items (content, isVisible) VALUES ('".$_POST['newcontent']."', 1)"; |
| 45 | $result = mysqli_query($cxn,$sql3); |
| 46 | if($result == false) { echo "Could not add new todo"; } |
| 47 | } |
| 48 | if (!empty($_POST['list'])) { |
| 49 | $sql4 = "SELECT * from things.items"; |
| 50 | $result = mysqli_query($cxn,$sql4); |
| 51 | if($result == false) { echo "Could not list all items. <a href='todo.php'>Back</a>"; } |
| 52 | else { |
| 53 | echo "<table border='1'>"; |
| 54 | echo "<tr><th>ID</th><th>Content</th><th>isVisible</th></tr>"; |
| 55 | for($i = 0; $i < mysqli_num_rows($result); $i++) |
| 56 | { |
| 57 | $row_array = mysqli_fetch_row($result); |
| 58 | echo "<tr>"; |
| 59 | for($j = 0;$j < mysqli_num_fields($result);$j++) |
| 60 | { |
| 61 | echo " <td>".$row_array[$j]."</td>\n"; |
| 62 | } |
| 63 | echo "</tr>"; |
| 64 | } |
| 65 | echo "</table><a href='todo.php'>Back</a>"; |
| 66 | } |
| 67 | } |
| 68 | if (empty($_POST['retr'])) { |
| 69 | if (empty($_POST['list'])) { |
| 70 | $sql="select iditems,content from things.items where isVisible = 1;"; |
| 71 | $result = mysqli_query($cxn,$sql); |
| 72 | if($result == false) |
| 73 | { |
| 74 | echo "<h4>Error: ".mysqli_error($cxn)."</h4>"; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | /* Table that displays the results */ |
| 79 | echo "<table> |
| 80 | "; |
| 81 | for($i = 0; $i < mysqli_num_rows($result); $i++) |
| 82 | { |
| 83 | echo " <tr> |
| 84 | "; |
| 85 | $row_array = mysqli_fetch_row($result); |
| 86 | for($j = 1;$j < mysqli_num_fields($result);$j++) |
| 87 | { |
| 88 | echo " <td><input type='checkbox' name='checkbox' value='".$row_array[$j-1]."' onClick='things.submit()'>".$row_array[$j]."</td>\n"; |
| 89 | } |
| 90 | } |
| 91 | echo " |
| 92 | </table> |
| 93 | Retrieve: <input type='text' name='retr' size=2><input type='submit' value=''><br> |
| 94 | New: <input type='text' name='newcontent'><input type='submit'><br> |
| 95 | <input type='submit' name='list' value='List'> |
| 96 | </body> |
| 97 | </html>"; |
| 98 | } } } |
| 99 | ?> |