gc40 Posted August 24, 2007 Share Posted August 24, 2007 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 }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/ Share on other sites More sharing options...
btherl Posted August 24, 2007 Share Posted August 24, 2007 Can you add "print $sql" before the mysql query in question, so we can see what query you are running? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332599 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332667 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 code is too long please paste only your prob... Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332669 Share on other sites More sharing options...
btherl Posted August 24, 2007 Share Posted August 24, 2007 I'm asking for you to print the query itself, not the query results $sql is the variable name you use for your queries. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332670 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 When trying to troubleshoot a query issue, one of the first things you should do is echo the query so you can see what is actually being sent to the database. echo $sql and post the results here Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332700 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 What line should i put the echo $sql on? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332704 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 <?php echo($sql); ?> echo ($sql); And both statements are returning nothing. The script itself is working great. Netasset and Nav are outputting and updating successfully... Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332707 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 You are setting $today as a formatted date string, but you don't use it anywhere. you are inserting $postdate into the DB. Could this have something to do with the issue? Don't use () with echo, it's unnecessary. <?php echo $sql; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332710 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 $sql = "update navs set NetAssets='$netassets',Nav='$nav', Offer='$offer', Date='$postdate', Bid='$bid' where id = '$id'"; echo $sql; what is the result of that? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332712 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 The only thing that is being output is the while statement information... Date | Net Assets | Nav | Action The information from the database is being output. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332717 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 ok, add the echo $sql right after the query I posted a minute ago and then run the file. You will see the query on screen. Copy and paste here so we can see what the query is actually returning. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332719 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 I got no problem with the PM, but if we keep the conversation here, then others may learn something. And I still did not see the query echo'd on screen Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332720 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332721 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 In order for that to echo, you will have to make that query actually run. It is an update query, so make sure the echo is there and then update a record. Once that query runs, it will print it on screen. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332722 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 update navs set NetAssets='4',Nav='4', Offer='', Date='', Bid='' where id = '40'update navs set NetAssets='4',Nav='4', Offer='', Date='', Bid='' where id = '40'The NAV was updated successfully. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332727 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332734 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 $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?? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332737 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 So don't set it then? Remove that line of code? What do you suggest? Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332738 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 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 }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332739 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332743 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 Can you suggest a solution, I am completely lost. I have tried everything I KNOW. I don't know what else to do to get postdate to output the date. p.s. It is in the right format, just not outputting a value when updating, only a NULL value (00-00-0000) Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332745 Share on other sites More sharing options...
keeB Posted August 24, 2007 Share Posted August 24, 2007 Just a quick general rule of thumb. Don't actually delete things, have a mark/flag which tells your client it's deleted (a status field, a bit column enabled, etc. Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332747 Share on other sites More sharing options...
chronister Posted August 24, 2007 Share Posted August 24, 2007 @keeB -- Why not actually delete things?? What is the problem of deleting things that you don't want in the DB anymore? I am curious about the logic behind this. I kinda like the idea too, seems like it could be very useful in some cases Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332750 Share on other sites More sharing options...
gc40 Posted August 24, 2007 Author Share Posted August 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66436-solved-date-giving-problem-in-php/#findComment-332752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.