...

View Full Version : Date Giving problem in PHP



gc40
08-24-2007, 03:57 AM
Hey All,
I am creating a script to add/edit/delete NET ASSET values for a website.
However, when I "update" the value of a net asset, the NAV and NETAsset output fine, however, the date is updated as 00-00-0000 rather than the actual date.
Can anyone look at my script and telling me why the date is outputting as 00-00-0000 rather than the date that is selected?




<?php

include ("config.php");
$today = date("Y-m-d");
$submit=$_REQUEST['submit'];
$id=$_REQUEST['id'];
$del=$_REQUEST['del'];
$netassets=$_REQUEST['netassets'];
$nav=$_REQUEST['nav'];
$day=$_REQUEST['day'];
$month=$_REQUEST['month'];
$year=$_REQUEST['year'];
if(isset($submit))
{
$fulldate = $year . "-" . $month . "-" . $date;

if($submit == 'Delete')
{
$sql = "delete from navs where id = '$id'";

$result = mysql_query($sql, $db);

if($result)
{
echo("The NAV was deleted successfully.");
echo("<form action='nav_index.php?action=editnav' method='POST'><p>");
echo("<input type='submit' name='submit' value='OK' class=\"submit button\"></form)");
}

}

else if($submit == 'Update')
{
$netassets=$_POST['netassets'];
$nav=$_POST['nav'];
$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
$fulldate=$_POST['fulldate'];
$postdate=$_POST['postdate'];

$sql = "update navs set NetAssets='$netassets',Nav='$nav', Offer='$offer', Date='$postdate', Bid='$bid' where id = '$id'";

$result = mysql_query($sql, $db);
if($result)
{
echo("The NAV was updated successfully.");
echo("<form action='nav_index.php?action=editnav' method='POST' onSubmit='fnsubmit()'>");
echo("<input type='submit' name='submit' value='OK' class=\"submit button\"></form)");
}

}



else if (($submit == 'Cancel') || ($submit == 'OK'))
{ //header("Location:http://www.bviddm.com/control/nav_index.php?action=editstory");
?>
<script language="Javascript" type="text/javascript">
document.location.href='nav_index.php?action=editnav'
</script>
<?
}
}


else
{
$netassets=$_POST['netassets'];
$nav=$_POST['nav'];
$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
$fulldate=$_POST['fulldate'];
$postdate=$_POST['postdate'];

if(isset($del))
{
$sql = "select * from navs where id = '$id'";
$navset = mysql_query($sql, $db);
$onenav = mysql_fetch_object($navset);
echo("Are you sure you want to delete the NAV ");
echo($onenav->id);
echo("?");
echo("<form action='nav_index.php?action=editnav' method='POST' onSubmit='fnsubmit()'>");
echo("<input type='hidden' name='id' value=" . $onenav->id . ">");
echo("<table><tr><td><input type='submit' name='submit' value='Delete' class=\"submit button\"></td><td><input type='submit' name='submit' value='Cancel' class=\"submit button\"></td></tr></table></form)");
}
else
{
if(isset($id))
{
$sql = "select * from navs where id = '$id'";
$navset = mysql_query($sql, $db);
$onenav = mysql_fetch_object($navset);
$postdate = $year."-".$month."-".$day;
list($year, $month, $day) = explode ("-", date("Y-m-d"));
?>

<form action= "nav_index.php?action=editnav" method="post">
<input type='hidden' name='id' value=<?php echo($id); ?>>
<table>
<tr><td>Day:</td><td>
<select name="day" id="day" value=<?php echo($day); ?>>
<?php
for ($i = 1; $i <= 31; $i++)
{
if ($i == $day) echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
else echo "<option value=\"$i\">$i</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Month:</td><td>
<select name="month" id="month" value=<?php echo($month); ?>>
<?php
$monthList=array(
1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December");

foreach($monthList as $code => $monthname)
{
if ($code == $month) echo "<option value=\"$code\" selected=\"selected\">$monthname</option>\n";
else echo "<option value=\"$code\">$monthname</option>\n";

}
?>
</select>
</td></tr>
<tr>
<td>Year:</td><td>
<select name="year" id="year" value=<?php echo($year); ?>>
<?php
$this_year = date("Y");
for ($i = $this_year; $i <= $this_year+10; $i++)
{
if ($i == $year) echo "<option value=\"$i\" selected=\"selected\">$i</option>\n";
else echo "<option value=\"$i\">$i</option>\n";
}
?>
</select></td>
</tr> <tr><td>Net Assets</td><td><input type="text" name="netassets" value=<?php echo($onenav->NetAssets);?>></td></tr>
<tr><td>Nav </td><td><input type="text" name="nav" value=<?php echo($onenav->Nav);?>></td></tr>
<tr><td colspan="2"><input type="submit" value="Update" name="submit" class="submit button"></td></tr>
</table>
</form>
<?php
}

else
{
?>

<table width="100%">
<tr><th class='right_title'>Date</th><th class='right_title'>Net Assets</th><th class='right_title'>Nav</th>
<th colspan=2><center>Action</center></th></tr>

<?php

$navquery = "select * from navs";

$navresult = mysql_query($navquery);
while ($row = mysql_fetch_object($navresult))
{
echo ("<tr>"."<td>".$row->Date."</td>"."<td>".$row->NetAssets."</td>"."<td>".$row->Nav."</td>");

echo("<td>"."<p align='center'>"."<a href='nav_index.php?action=editnav&id=$row->id'>"."<img src='..\images\button_edit.png' border='0' alt="."Edit".">"."</td>".
"<td><p align='center'>"."<a href='nav_index.php?action=editnav&id=$row->id&del=$row->id'>"."<img src='..\images\button_drop.png' border='0' alt="."Delete"."></td></tr>");
}

}
?>


</table>
<?php

}} ?>

Mwnciau
08-24-2007, 05:52 AM
Where is the input field for postdate?

gc40
08-24-2007, 06:39 AM
$postdate = $year."-".$month."-".$day;

PappaJohn
08-24-2007, 08:18 AM
$postdate=$_POST['postdate'];

$sql = "update navs set NetAssets='$netassets',Nav='$nav', Offer='$offer', Date='$postdate', Bid='$bid' where id = '$id'";

Right before updating the db, you set $postdat=$_POST['postdate'] yet your input form has no 'postdate' field.

Earlier in the code you set $fulldate to the month-day-year value.

Well, almost


$day=$_REQUEST['day'];
$month=$_REQUEST['month'];
$year=$_REQUEST['year'];
if(isset($submit))
{
$fulldate = $year . "-" . $month . "-" . $date;

CFMaBiSmAd
08-24-2007, 08:32 AM
I recommend turning on full php error reporting to help find these type of variable naming and referencing errors.

usik
08-24-2007, 01:28 PM
$fulldate = date("Y-m-d");
That would be so much quicker than setting all those variables



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum