Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date Giving problem in PHP

    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 Code:

    <?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(
                
    => "January",
                
    => "February",
                
    => "March",
                
    => "April",
                
    => "May",
                
    => "June",
                
    => "July",
                
    => "August",
                
    => "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

    }} ?>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Where is the input field for postdate?

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $postdate = $year."-".$month."-".$day;

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    PHP Code:
    $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.

    Edit: Well, almost

    Code:
    $day=$_REQUEST['day'];
    $month=$_REQUEST['month'];
    $year=$_REQUEST['year'];
    if(isset($submit))
    {
        $fulldate = $year . "-" . $month . "-" . $date;
    Last edited by PappaJohn; 08-24-2007 at 07:20 AM. Reason: added more info

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    I recommend turning on full php error reporting to help find these type of variable naming and referencing errors.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
    $fulldate date("Y-m-d"); 
    That would be so much quicker than setting all those variables


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •