Jump to content

Recommended Posts

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

}} ?>

Link to comment
https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/
Share on other sites

Nothing is being output :S I am using this script to update the values of selected fields, not output anything. All I need help with is one simple date value.

 

It works when outputting just fine.

If it is January 1st, 2001, then it would output 01-01-2001, However, when I go to update that said field, it would change the 01-01-2001 to 00-00-0000

 

HELP, PLEASE>

The reason for the PM is because I don't want the link to be posted up. I figured you could help better with seeing the link. I did put the ECHO statement with the $sql variable in there. Thats the problem, nothing is outpuutting other than the usual information.

update navs set NetAssets='4',Nav='4', Date='' where id = '40'update navs set NetAssets='4',Nav='4', Date='' where id = '40'

 

 

Okay, I see the problem, nothing is being output to Date.

 

However, I have the variable:

$postdate = $year."-".$month."-".$day;

 

Which should combine year, month and day to form 00-00-0000, but its not working. Anyone have an idea why?

$postdate=$_POST['postdate']; <-- Here your setting $postdate, and using it right after.

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

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

 

Is the postdate field displaying in the correct format??

HERE IS THE NEW CODE:


<?php
//error_reporting(E_ALL);
include ("../class/config.php");
$today = date("Y-m-d");

$submit=$_REQUEST['submit'];
$id=$_REQUEST['id'];
$del=$_REQUEST['del'];
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'];

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

echo $sql;

	$result = mysql_query($sql, $db);
	if($result)
	{
		echo $sql;
		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
{

if(isset($del))
{
	$sql = "select * from navs where id = '$id'";
	$navset = mysql_query($sql, $db);
	$onenav = mysql_fetch_object($navset);
	echo ($sql);
	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'";
$postdate = $year."-".$month."-".$day;
$navset = mysql_query($sql, $db);
$onenav = mysql_fetch_object($navset);
list($year, $month, $day) = explode ("-", date("Y-m-d"));
		?>
<?php echo($sql); ?>			
<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

}} ?>

Whether you set it or not is your choice. You are still trying to explicitly update that field to NULL which is going to produce 00-00-0000.

 

If you want the date to be updated to the correct date, then I would make sure that $postdate is displaying the data in the format you want it in.

Why would I want a status field? I don't want to have extra database entries that are not need. Especially if the database size gets too big. The only reason I can see keeping deleted entries is for backup/accidentals deletion purposes.

 

Getting back to my main problem though. How do I get date to output the date value combined of Year, Month and Day in the format 00-00-0000

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.