Hey there,
I am a super newb looking to get started with PHP. I work as an ASP developer so I guess it is a bit similar in many ways. I want to start by creating a simple to do list webpage where I can enter in tasks, and view what I've accomplished and yet to accomplish.
I have already setup the table 'todolist' in the database as follows:
id (primary key), date, duedate, task, status
I was reading some tutorials at a beginner website, and got to the point where I have a page for adding and a page for viewing. I would like to combine both into one page where I have the add task at the top and the task list below, the newest at the top and the oldest at the bottom.
Here is a mockup image of what I hope to make:
http://xs410.xs.to/xs410/06494/todomockup.gif
For editing, I am unsure of the best way to do this, I guess it would make a popup window with the 4 input boxes, and then have an Save or Delete button.
here is the code I have for the view.php so far:
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT date, duedate, task, status FROM todolist";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "date :{$row['date']} <br>" .
"duedate : {$row['duedate']} <br>" .
"task : {$row['task']} <br>" .
"status : {$row['status']} <br><br>";
}
include 'closedb.php';
?>
and here is the code for the todo.php adding page which doesn't even work properly, gives me an error every time I submit a new task, but still somehow goes into the database...
<html>
<head>
<title>Todo List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if(isset($_POST['add']))
{
include 'library/config.php';
include 'library/opendb.php';
$date = $_POST['date'];
$duedate = $_POST['duedate'];
$task = $_POST['task'];
$status = $_POST['status'];
$query = "INSERT INTO todolist (date, duedate, task, status) VALUES ('$date', '$duedate, '$task', '$status')";
mysql_query($query) or die('Error, insert query failed');
$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');
include 'library/closedb.php';
echo "New Task added";
echo "$query";
}
else
{
?>
<form method="post">
<table width="808" border="1" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Date</td>
<td><input name="date" type="text" id="date"></td>
<td width="100">Due Date</td>
<td><input name="duedate" type="text" id="duedate"></td>
<td width="400">Task</td>
<td><input name="task" type="text" id="task"></td>
<td width="100">Status</td>
<td><input name="status" type="text" id="status"></td>
<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Add Task"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
I tried to see what the query was by doing echo "$query"; , which I guessed was the way to do "response.write query" but it doesn't spit anything out, so it must be wrong. 😕 Any help would be appreciated! thanks 🙂