Home arrow PHP arrow Page 2 - Viewing and Editing Tasks for a Project Management Application

The edit_task script - PHP

Welcome to the fifth part of a seven part series on building a project management application. In the last article we looked at the view_tasks.php script. Specifically, we looked at the PHP portion of the script in detail. In this article we will finish discussing that script by examining the HTML portion. We will then move on to discuss the edit_task.php script, which is responsible for handling any changes that the user makes to a task.

TABLE OF CONTENTS:
  1. Viewing and Editing Tasks for a Project Management Application
  2. The edit_task script
  3. Script Explained
  4. HTML Form
By: David Web
Rating: starstarstarstarstar / 2
June 30, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The edit_task.php script is responsible for updating the tasks table whenever you make any changes to a task. Its main role is to display an HTML form that contains the information about the task you want to change and then sends that information to the database. Below is a screen shot of the edit_task.php page:

And here's the code for the entire script:


<?php

include "dbcon.php";

include "functions.php";

$cpid=mysql_escape_String($_GET['pid']);

$tpid=mysql_escape_String($_GET['tid']);



$getname = "SELECT title FROM projects WHERE pid = '".$cpid."'";

$g_result = mysql_query($getname);

if(!$g_result){

echo mysql_error();

}else{

$rowname = mysql_fetch_assoc($g_result);

$title = $rowname['title'];

}


$gettask= "SELECT * FROM tasks WHERE tid = '".$ctid."'";

$t_result = mysql_query($gettask);

if(!$t_result){

echo mysql_error();

}else{

$rowtask = mysql_fetch_assoc($t_result);

}



if(isset($_POST['submit'])){

//check vars

$descr=mysql_escape_string($_POST['descr']);

$p_pid=mysql_escape_string($_POST['p_pid']);


//build date

$duedt = $_POST['yy'] . "-";

if($_POST['mm'] < 10) {

$duedt .= "0";

}

$duedt .= $_POST['mm'] . "-";

if($_POST['mm'] == 4 || $_POST['mm'] == 6 || $_POST['mm'] == 9 || $_POST['mm'] == 11) {

if($_POST['dd'] > 30) {

$duedt .= "30";

} else {

$duedt .= $_POST['dd'];

}

} elseif($_POST['mm'] == 2) {

if($_POST['yy'] == 2008 || $_POST['yy'] == 2012) {

if($_POST['dd'] > 29) {

$duedt .= "29";

} else {

$duedt .= $_POST['dd'];

}

} else {

if($_POST['dd'] > 28) {

$duedt .= "28";

} else {

$duedt .= $_POST['dd'];

}

}

} else {

$duedt .= $_POST['dd'];

}

 

//insert

$insert = "INSERT INTO tasks SET task_description = '".$descr."',";

$insert .= "complete_by = '".$duedt."',p_id= '".$p_pid."'";

if(!mysql_query($insert)){

echo mysql_error();

}

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/PM_Main.dwt.php" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>Untitled Document</title>

<!-- InstanceEndEditable -->

<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->

<link href="Templates/main.css" rel="stylesheet" type="text/css" />

</head>


<body>

<table width="100%" border="0">

<tr>

<td width="33%">&nbsp;</td>

<td width="28%">&nbsp;</td>

<td width="39%">Logged in: <!-- InstanceBeginEditable name="login" --><? echo $_SESSION['name'];?> | <a href="logout.php">Logout</a><!-- InstanceEndEditable --></td>

</tr>

<tr>

<td colspan="3" bgcolor="#6699CC" class="headertxt">Project Management Software </td>

</tr>

<tr>

<td colspan="3"><!-- InstanceBeginEditable name="main" -->

<form id="form1" name="form1" method="post" action="edit_task.php">

<table width="100%" border="0">

<tr>

<td colspan="2" class="loginheader"><?php echo $title;?></td>

</tr>

<tr>

<td width="14%">&nbsp;</td>

<td width="86%">&nbsp;</td>

</tr>

<tr>

<td valign="top">Description</td>

<td><label>

<textarea name="descr"><?php echo $rowtask['task_description'];?></textarea>

</label></td>

</tr>

<tr>

<td valign="top">Complete by: </td>

<td><label>

<?

$dd = date("d");

$mm = date("m");

$yy = date("Y");

echo "<select name="dd">n";

for($i = 1; $i <= 31; $i++) {

echo "<option value="" . $i . """;

if($i == $dd) {

echo " selected";

}

echo ">" . $i . "</option>n";

}

echo "</select>&nbsp;<select name="mm">n";

for($i = 1; $i <= 12; $i++) {

echo "<option value="" . $i . """;

if($i == $mm) {

echo " selected";

}

echo ">" . $month_names[$i] . "</option>n";

}

echo "</select>&nbsp;<select name="yy">n";

for($i = $yy; $i <= ($yy + 1); $i++) {

echo "<option value="" . $i . """;

if($i == $yy) {

echo " selected";

}

echo ">" . $i . "</option>n";

}

echo "</select>";

?>

</label>

<input name="p_pid" type="hidden" value="<?php echo $_GET['pid']?>" /></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><label>

<input name="submit" type="submit" id="submit" value="Update Task" />

</label></td>

</tr>

</table>

</form>

 

<!-- InstanceEndEditable --></td>

</tr>

<tr>

<td colspan="3"><!-- InstanceBeginEditable name="nav" --><table width="100%" border="0">

<tr>

<td><a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a></td>

</tr>

</table><!-- InstanceEndEditable --></td>

</tr>

<tr>

<td align="right" class="cright" colspan="3">copyright &copy; 2007 PM </td>

</tr>

</table>

</body>

<!-- InstanceEnd --></html>



 
 
>>> More PHP Articles          >>> More By David Web
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: