PDA

View Full Version : Jason's Calendar , PHP , MSQL Help please?



nmb
08-06-2007, 11:29 AM
1) Script Title: Jason's Date Input Calendar

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamici...oncalendar.htm

3) Describe problem: Can't fetch date from database

Hello, i know lots of posts have been made on this subject but there is no definitive answer i can find which has lead me to solving my problem.

I have set up jasons calendar on my php form, and i can successfully pass the date through the form field to my mysql database:
------------------------
<script>DateInput('job_deadline', true ,'YYYY-MM-DD')</script>
------------------------


However, althought i can pass the date to the database, i cannot fetch the date on my other php page... i have a variable called $job_deadline, and i have placed this in the script. but all i get is a message in my browser saying the date is not properly formatted and as such it returns todays date.

I cannot understand how the date isnt formatted properly, considering the date is YYYY-MM-DD by default in the database and also in jasons script.

i know the code should work because i can collect the date from the database without jasons script, and just using a text box form field... so why does it not work... any ideas? here is my script (its a form for editing database fields)
----------------------------


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>edit job</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/calendarDateInput.js">
/***********************************************
* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.
***********************************************/
</script>
</head>
<body>
<table width="629" border="0" cellpadding="2" cellspacing="1">
<tr>
<td><a href="index.php"><img src="images/icon_schedule.png" alt="Job Schedule" width="16" height="16" border="0" /></a> <a href="index.php">Job Schedule</a> <img src="images/icon_add.png" alt="Add Job" width="16" height="16" hspace="2" border="0" /> <a href="job_add.php">Add Job</a> <img src="images/icon_edit.png" alt="Edit Job" width="16" height="16" hspace="4" /> <a href="job_edit.php">Back to Edit List</a> </td>
</tr>
</table>
<?
// connect to mysql
mysql_connect("") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

// If cmd has not been initialized
if(!isset($cmd))
{

// query the schedule
$result = mysql_query("select * from schedule order by job_number");


// display a heading
echo "<br><br>Choose a Job to Edit:<br><br>";

// run the while loop that grabs all table columns required
while($r=mysql_fetch_array($result))
{
// grab the fields and set variables
$id=$r["id"];
$job_number=$r["job_number"];
$job_description=$r["job_description"];
$job_date_added=$r["job_date_added"];
$job_deadline=$r["job_deadline"];
$notes=$r["notes"];
$priority=$r["priority"];

// make the job edit title heading a link

echo "<a href='job_edit.php?cmd=edit&id=$id'>$job_number</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM schedule WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form method="post" action="job_edit.php">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<table width="629" border="0" cellpadding="2" cellspacing="1">
<tr>
<td><strong>Edit Job Details</strong></td>
</tr>
</table>
<br />
<table width="629" border="0" cellspacing="1" cellpadding="2">
<tr>
<td valign="middle">Job Number </td>
<td width="494" valign="middle">
<INPUT TYPE="TEXT" NAME="job_number" VALUE="<?php echo $myrow["job_number"] ?>"></td>
</tr>

<tr>
<td width="124" valign="top">Job Description</td>
<td valign="top">
<TEXTAREA NAME="job_description" COLS=50 ROWS=8 id="job_description"><? echo $myrow["job_description"] ?></TEXTAREA></td>
</tr>

<tr>
<td valign="middle">Job Deadline</td>
<td valign="middle"><script>DateInput('job_deadline', true ,'YYYY-MM-DD', <? echo $myrow["job_deadline"] ?>)</script></td>
</tr>
<tr>
<td valign="top">Notes</td>
<td valign="top">
<TEXTAREA NAME="notes" COLS=50 ROWS=8 id="notes"><? echo $myrow["notes"] ?></TEXTAREA></td>
</tr>
<tr>
<td width="124" valign="middle"><p>Job Priority</p> </td>
<td valign="middle"><label>
<select name="priority" id="priority">
<option value="<? echo $myrow["priority"] ?>" selected="selected"><? echo $myrow["priority"] ?></option>
<option value="1 = Urgent">1 = Urgent</option>
<option value="2 = As Deadline">2 = As Deadline</option>
<option value="3 = On Hold">3 = On Hold</option>
<option value="4 = Complete">4 = Complete</option>
</select>
</label></td>
</tr>
<tr>
<td width="124">&nbsp;</td>
<td> <input type="hidden" name="cmd" value="edit">

<input type="submit" name="submit" value="Submit Changes"></td>
</tr>
</table>
</form>
<? } ?>

<?
if ($_POST["submit"])
{
$job_number = $_POST["job_number"];
$job_description = $_POST["job_description"];
$job_deadline = $_POST["job_deadline"];
$notes = $_POST["notes"];
$priority = $_POST["priority"];

$sql = "UPDATE schedule SET job_number='$job_number',job_description='$job_description',job_deadline='$job_deadline', notes='$notes', priority='$priority' WHERE id=$id";

$result = mysql_query($sql);
echo "<BR>&nbsp; - Thank you! Job Updated<BR><BR>";
// echo "<a href='job_edit.php' class='headlines'>Edit Another Article</a>";
}
}
?>
</body>
</html>