0

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)

      <div>
        <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>
            </div>
            <input type="submit" value="Save" class="save" name="febsave">
        </div>
        <table border="1" rules="groups" cellpadding="10px;" class="tableincome">
        <thead>
            <th>Monthly Salary</th>
            <th></th>
            <th>RM</th>
        </thead>
        <tr>
            <td>Royalty</td>
            <td></td>
            <td><center><input type="text" placeholder="0" name="febroyalty" size="11" value="<?php if(isset($_POST['febroyalty'])){echo htmlentities($_POST['febroyalty']);} ?>"></center></td>
        </tr>
        <tr>
            <td>Subletting/Rent</td>
            <td></td>
            <td><center><input type="text" placeholder="0" name="febsub" size="11" value="<?php if(isset($_POST['febsub'])){echo htmlentities($_POST['febsub']);} ?>"></center></td>
        </tr>
        <tr>
            <td>Others(Unit Trust/Emas/IPO/etc)</td>
            <td></td>
            <td><center><input type="text" placeholder="0" name="febothers" size="11" value="<?php if(isset($_POST['febothers'])){echo htmlentities($_POST['febothers']);} ?>"></center></td>
        </tr>
        </table>
        </form>
      </div>
    </div>

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:

if(isset($_POST['febsave']))
{
    $febroyalty = $_POST['febroyalty'];
    $febsub = $_POST['febsub'];
    $febothers = $_POST['febothers'];

    if($febroyalty&&$febsub&&$febothers)
    {
        require "connect.php";
        $febtotal=($febroyalty + $febsub + $febothers);
        $query=("INSERT INTO feb VALUES ('$febroyalty','$febsub','$febothers','$febtotal')");
        $febresult=mysql_query($query);
    }
    else
    {
        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

3
Contributors
3
Replies
42
Views
4 Years
Discussion Span
Last Post by JorgeM
0

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

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

</form>

Edited by urtrivedi

0

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>')?>">

js:

function date_time(id)
{
        date = new Date;
        year = date.getFullYear();
        d = date.getDate();
        result = '+year+';
        document.getElementById(id).innerHTML = result;
        setTimeout('date_time("'+id+'");','1000');
        return true;
}

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.