So im not too sure if im posting this in the right forum. please dont be angry! new at daniweb

so basically what i wanna know is how to save real time date into database.

what i have is a page with tabs of month and in each tab the content consists of a form and in the form theres a table and save button and also coding to display real time(year)

tab (month feb)

   <div class="tabContent" id="feb">

      <center><h2>February <span id="year"><script type="text/javascript">document.write(new Date().getFullYear())</script></span></h2></center>   <---real time(year)

        <form method="post" action="income.php">
        <div style="height:0px;">
            <div class="rmtotal">
            <?php if(@$febresult) ?>
            <h3>Your Total Income :</br> <?php echo "RM ".@$febtotal?></h3>
            <input type="submit" value="Save" class="save" name="febsave">
        <table border="1" rules="groups" cellpadding="10px;" class="tableincome">
            <th>Monthly Salary</th>
            <td><center><input type="text" placeholder="0" name="febroyalty" size="11" value="<?php if(isset($_POST['febroyalty'])){echo htmlentities($_POST['febroyalty']);} ?>"></center></td>
            <td><center><input type="text" placeholder="0" name="febsub" size="11" value="<?php if(isset($_POST['febsub'])){echo htmlentities($_POST['febsub']);} ?>"></center></td>
            <td>Others(Unit Trust/Emas/IPO/etc)</td>
            <td><center><input type="text" placeholder="0" name="febothers" size="11" value="<?php if(isset($_POST['febothers'])){echo htmlentities($_POST['febothers']);} ?>"></center></td>

i was thinking that after the user has clicked on save button it will save all user input along with the real-time(year) into a table in the database. right now my php coding only saves the text box values:

    $febroyalty = $_POST['febroyalty'];
    $febsub = $_POST['febsub'];
    $febothers = $_POST['febothers'];

        require "connect.php";
        $febtotal=($febroyalty + $febsub + $febothers);
        $query=("INSERT INTO feb VALUES ('$febroyalty','$febsub','$febothers','$febtotal')");
        echo ("<b>Please fill out the entire form.</b>");

but i also wanna be able to save the year into the database. is that possible? or is there a diff way of doing the whole real time date thing? or any improvement in my coding in general. noob

Recommended Answers

All 3 Replies

instead of span you must use form element like text or hidden
hidden is best for your case
your element must be in between form tag

<type =hidden id=year name =year value='<?php echo date("Y"); ?>'>


i tried doing this and even changed the coding for js:

<input type="hidden" id="date_time" value="<?php echo ('<span id="date_time"></span><script type="text/javascript">window.onload = date_time("date_time");</script>')?>">


function date_time(id)
        date = new Date;
        year = date.getFullYear();
        d = date.getDate();
        result = '+year+';
        document.getElementById(id).innerHTML = result;
        return true;

and it didnt work. my coding probably looks ridiculous too. sorry. :s

If you want to display the current year on the page, you can do so client or server side. Since you are already writing PHP code, just echo the year: date("Y"); To save the year in the database, include a variable in your insert string that contains the value of the year. Again, you can access the year by using and formatting via the date() method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.