hello,

I am building a mysql/php/javascript based online timesheet system which allows users to assign themselves predefined projects and then select one of the projects assigned to them and add hours for a particular date to the database - i can get the add to work fine, but i need to be able to amend the hours once they have been entered (i.e. go back to the same form, read the existing hours in and then allow the user to edit them via the form then update the database record)

I have a javascript based calendar which changes the content of an anchor tag without refreshing the page i.e.
initially:-
<a id="tag">12/12/2007</a>
then click "change date" the calendar pops up, you can click a date and then it closes the calendar popup and updates the content of the <a> tag WITHOUT refreshing the page. The fact that it doesnt refresh the page is important and needs to stay this way.

I need to be able to read the content of the <a> tag when it changes and read it into a php variable (which in turn affects an SQL statement)

it would be nice to ba able update the $date variable (which is initially set using $_GET . onchange() of the <a> tag's content. but i dont think you can do this!

Here is the code for my page, im sure its pretty messy and does things in an over complicated way, but it works (so far)!:

<?php
  ob_start();
  session_start();
  
  $connect = mysql_connect('localhost', 'root', '');
  if(!$connect){
    die("sql connection error");
  }
  $username = $_SESSION['username'];
  mysql_select_db('timesheet');
  $sqlUser = "select * from user where Username='".$_SESSION['username']."';";
  $queryUser = mysql_query($sqlUser);
  
?>
<html>
  <head>
    <title>Impetus online project timesheet</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script>
    function readDate(elem){
      var ele = document.getElementById(elem);
      var childNodes = ele.childNodes[0];
      var element = childNodes.nodeValue
      document.hours.date.value=element;
    }
    
      function getDate(){
        var todaysDate;
        var currentTime = new Date();
        var day = currentTime.getDate();
        var month = currentTime.getMonth()+1;
        var year = currentTime.getFullYear();
        todaysDate= window.location ="addHours.php?date="+day+"/"+month+"/"+year;
        return todaysDate;    
      }
    </script>
  </head>
  <body>
  <script type='text/JavaScript' src='scw.js'></script>
  <!-- start of container table -->
    <table class="tablestyle" width="800px" align="center" border="1">
      <tr>
        <td align="center" class="cellstyle"><img src="img/impetuslogo.png"></td>
      </tr>
      <tr><td class="cellstyle">
      <!-- start of content table -->
        <table align="center" width="100%" border="0">
            <tr>
              <td align="center" colspan="2"><h1>Welcome to the Impetus Online Timesheet</h1></td>
            </tr>
            
            <tr>
              <td rowspan="5" width="20%" class="tablestyle1" valign="top">
                <!-- start of nav table -->
                <table width="100%">
                  
                  <?php if(isset($_SESSION['username'])){?>
                  <tr>
                    <td class="cellstyle1" align="center">
                      <?php 
                          echo 'Hello '.$username;
                      ?>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="yourProjects.php">Your Projects</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="#">Your Hours</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a onclick="return getDate();" href="#">Add Hours</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="#">Create a Report</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="addProject.php">Add a new Project</a>
                    </td>
                  </tr>
                </table>
                <!-- end of nav table -->
              </td>
              <td class="tablestyle1">
              <!-- start of inner content table -->
                <table width="100%" border="0">
                  <tr>
                    <td colspan="4">
                      <p>Select the project you wish to add hours for - Please note you can change the projects you are enrolled on in <b>"Your Projects"</b>.</p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                  </tr>
                  <tr>
                    <td width="10%">
                      <p><b>Project:</b></p>
                    </td>
                    <form name="projName" action="addHours.php" method="get">
                    <input type="hidden" id="hiddendate" name="hiddendate">
                    <?php
                    $projectName= Array();
                    $counter=0;
                    $date=$_GET['date'];
                      while($row = mysql_fetch_array($queryUser)) {
                        for($i=0;$i<15;$i++){
                          $projectName[$i] = $row['Project'.($i+1)];
                          if($projectName[$i]!=="" && isset($projectName[$i])){
                            if($counter>=3){
                            echo'
                            </tr><tr><td></td>
                            <td>
                              <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
                            </td>
                            ';
                            $counter=0;
                            }
                            else if($counter<3){
                            echo'
                            <td>
                              <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
                            </td>
                            ';
                              $counter++;
                            }
                          }
                          //else{echo'empty';}
                        }
                      }
                      $explodedGet = explode("%20", $_GET['projectName']);
                      for($t=0;$t<count($explodedGet);$t++){
                          $trim= $trim.$explodedGet[$t]." ";
                      }
                      $pName= rtrim($trim);
                  if(isset($pName) && $pName!==""){
                   ?>
                   
                   </tr>
                   <tr>
                        <td colspan="2" align="center">
                          <p>Add your hours for <a id='aTest'><?php echo $date; ?></a></p>
                          
                        </td>
                        <td colspan="2" align="center">
                          <a href='javascript:scwShow(scwID("aTest"),scwID("aTest"));' :mrgreen:***THIS IS WHRE THE CALENDAR IS CALLED ***:mrgreen: onclick=>Click here to change the date</a>
                        </td>
                      </tr>
                  
                  <tr>
                    <td colspan="4">
                      <table width="100%">
                        <tr>
                          <td colspan="2" height="30px">
                            Currently Select Project: <b><?php echo $pName; ?></b>
                          </td>
                        </tr>
                        <tr>
                          <td width="30%">
                            <p>Type of work</p>
                          </td>
                          <td width="30%">
                            <p>Hours</p>
                          </td>
                          <td width="40%">
                            <p>Notes</p>
                          </td>
                        </tr>
                        </form>
                        <form name="hours" method="get" action="addHoursDB.php">
                        <input type="hidden" name="date" value="bolocks">
                        <?php
:mrgreen:***this function checks to see if a record already exists for the username, date and project that are currently selected ***:mrgreen:
                          function exists(){
                            $sqlexists = "select Date from day where Username='".$_SESSION['username']."';";
                            if($existsQuery = mysql_query($sqlexists) or die("there was an error")){
                              //echo'inside if statement';
                              while($check = mysql_fetch_array($existsQuery)){
                                $datecheck = $check['Date'];
                                //echo'inside while loop';
                                if($date == $datecheck){
                                 $exists = true; 
                                 //echo'the record already exists';
                                 break;
                                }
                                else if($date !==$datecheck){
                                  $exists = false;
                                }
                              }
                            }
                            return exists;
                          }
                          if(exists()==false){
                          echo'<tr><td colspan="4">You have not added any hours for this project on this date yet, so you have been taken into the "normal mode"</td></tr>';
                            $sqlProject = "select * from project where ProjectName like '%".$pName."%';";
                            $queryProject = mysql_query($sqlProject) or die(mysql_error());
                            $workType= Array();
                            while($proj = mysql_fetch_array($queryProject)){
                              //echo'here';
                              for($r=0;$r<10;$r++){
                                //echo "WorkType: ".$proj['WorkType1'];
                                $workType[$r] = $proj['WorkType'.($r+1)];
                                if(isset($workType[$r]) && $workType[$r]!==""){
                                  echo'
                                      <tr>
                                        <td>
                                          <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
                                        </td>
                                        <td>
                                          <p>Hrs: <select name="hoursHours'.($r+1).'"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option></select> Mins: <select name="hoursMins'.($r+1).'"><option>0</option><option>15</option><option>30</option><option>45</option></select></p>
                                        </td>
                                        <td>
                                          <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
                                        </td>
                                      </tr>
                                  ';
                                }
                                else{break;}
                              }
                            }
                          }
                          else if(exists()==true){
                          echo'<tr><td colspan="4">You have already added hours for this project on this date, so you have been taken into the "amend mode"</td></tr>';
                          $_SESSION['dayexists']='true';
                            $sqlProject = "select * from day where Date='".$Date."' AND ProjectName like '%".$pName."%' AND Username='".$_SESSION['username']."';";
                            
                            $queryProject = mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
                            mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
                            $workType= Array();
                            while($proj = mysql_fetch_array($queryProject)){
                              echo'here';
                              for($r=0;$r<10;$r++){
                                //echo "WorkType: ".$proj['WorkType1'];
                                $workType[$r] = $proj['WorkType'.($r+1)];
                                if(isset($workType[$r]) && $workType[$r]!==""){
                                  echo'
                                      <tr>
                                        <td>
                                          <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
                                        </td>
                                        <td>
                                          <p>Hrs: <select name="hoursHours'.($r+1).'"><option></option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option></select> Mins: <select name="hoursMins'.($r+1).'"><option></option><option>15</option><option>30</option><option>45</option></select></p>
                                        </td>
                                        <td>
                                          <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
                                        </td>
                                      </tr>
                                  ';
                                }
                                else{break;}
                              }
                            }
                          }
                          
                          ?>
                          <tr>
                            <td>
                          <input type="hidden" name="projectName" value="<?php echo $pName; ?>"><input type="submit" value="Submit" name="submit" onclick="readDate('aTest')">
                            </td>
                          </tr>
                          </table>
                            </td>
                            </tr>     
                            </form>
                          </table>
                          <!-- end of inner content table -->
                          <?php
                          
                    }
            }
            else{echo "<tr><td>You are not logged in. Click <a href='index.php'>here</a> to log in.</td></tr>";}
            echo'
              </td>
            </tr>
        </table>
        <!-- end of content table -->
      </td></tr>
    </table>
    <!-- end of container table -->
  </body>
</html>
';
?>

The problem at the moment is becuase when the page loads it gets todays date (a date has to be supplied to the javascript calendar before you pick a different date, so i pass todays date in the url from the previous page)
So once you have added some information for a particular date with a particular username and a particular project title, the script always thinks you have already added hours for that day and goes into the "amend/edit" block of code. I need to be able to change the date using the calendar then the method exists() to be called and passed the new date (which will then mean the method wont find an existing record and will jump to the "new hours" type block)

I know this is pretty long and maybe too complex, but i have been trying to find a solution for a while now and its getting really annoying!

I hope this makes sense!

Please help!!!!!

Thanks,

Mike

Recommended Answers

All 4 Replies

Hi!

Have you tried using $_REQUEST as the new date seems to be placed in the address bar. PHP should read it from there.

hello,

I am building a mysql/php/javascript based online timesheet system which allows users to assign themselves predefined projects and then select one of the projects assigned to them and add hours for a particular date to the database - i can get the add to work fine, but i need to be able to amend the hours once they have been entered (i.e. go back to the same form, read the existing hours in and then allow the user to edit them via the form then update the database record)

I have a javascript based calendar which changes the content of an anchor tag without refreshing the page i.e.
initially:-
<a id="tag">12/12/2007</a>
then click "change date" the calendar pops up, you can click a date and then it closes the calendar popup and updates the content of the <a> tag WITHOUT refreshing the page. The fact that it doesnt refresh the page is important and needs to stay this way.

I need to be able to read the content of the <a> tag when it changes and read it into a php variable (which in turn affects an SQL statement)

it would be nice to ba able update the $date variable (which is initially set using $_GET . onchange() of the <a> tag's content. but i dont think you can do this!

Here is the code for my page, im sure its pretty messy and does things in an over complicated way, but it works (so far)!:

<?php
  ob_start();
  session_start();
  
  $connect = mysql_connect('localhost', 'root', '');
  if(!$connect){
    die("sql connection error");
  }
  $username = $_SESSION['username'];
  mysql_select_db('timesheet');
  $sqlUser = "select * from user where Username='".$_SESSION['username']."';";
  $queryUser = mysql_query($sqlUser);
  
?>
<html>
  <head>
    <title>Impetus online project timesheet</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script>
    function readDate(elem){
      var ele = document.getElementById(elem);
      var childNodes = ele.childNodes[0];
      var element = childNodes.nodeValue
      document.hours.date.value=element;
    }
    
      function getDate(){
        var todaysDate;
        var currentTime = new Date();
        var day = currentTime.getDate();
        var month = currentTime.getMonth()+1;
        var year = currentTime.getFullYear();
        todaysDate= window.location ="addHours.php?date="+day+"/"+month+"/"+year;
        return todaysDate;    
      }
    </script>
  </head>
  <body>
  <script type='text/JavaScript' src='scw.js'></script>
  <!-- start of container table -->
    <table class="tablestyle" width="800px" align="center" border="1">
      <tr>
        <td align="center" class="cellstyle"><img src="img/impetuslogo.png"></td>
      </tr>
      <tr><td class="cellstyle">
      <!-- start of content table -->
        <table align="center" width="100%" border="0">
            <tr>
              <td align="center" colspan="2"><h1>Welcome to the Impetus Online Timesheet</h1></td>
            </tr>
            
            <tr>
              <td rowspan="5" width="20%" class="tablestyle1" valign="top">
                <!-- start of nav table -->
                <table width="100%">
                  
                  <?php if(isset($_SESSION['username'])){?>
                  <tr>
                    <td class="cellstyle1" align="center">
                      <?php 
                          echo 'Hello '.$username;
                      ?>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="yourProjects.php">Your Projects</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="#">Your Hours</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a onclick="return getDate();" href="#">Add Hours</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="#">Create a Report</a>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" class="cellstyle1">
                      <a href="addProject.php">Add a new Project</a>
                    </td>
                  </tr>
                </table>
                <!-- end of nav table -->
              </td>
              <td class="tablestyle1">
              <!-- start of inner content table -->
                <table width="100%" border="0">
                  <tr>
                    <td colspan="4">
                      <p>Select the project you wish to add hours for - Please note you can change the projects you are enrolled on in <b>"Your Projects"</b>.</p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                  </tr>
                  <tr>
                    <td width="10%">
                      <p><b>Project:</b></p>
                    </td>
                    <form name="projName" action="addHours.php" method="get">
                    <input type="hidden" id="hiddendate" name="hiddendate">
                    <?php
                    $projectName= Array();
                    $counter=0;
                    $date=$_GET['date'];
                      while($row = mysql_fetch_array($queryUser)) {
                        for($i=0;$i<15;$i++){
                          $projectName[$i] = $row['Project'.($i+1)];
                          if($projectName[$i]!=="" && isset($projectName[$i])){
                            if($counter>=3){
                            echo'
                            </tr><tr><td></td>
                            <td>
                              <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
                            </td>
                            ';
                            $counter=0;
                            }
                            else if($counter<3){
                            echo'
                            <td>
                              <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
                            </td>
                            ';
                              $counter++;
                            }
                          }
                          //else{echo'empty';}
                        }
                      }
                      $explodedGet = explode("%20", $_GET['projectName']);
                      for($t=0;$t<count($explodedGet);$t++){
                          $trim= $trim.$explodedGet[$t]." ";
                      }
                      $pName= rtrim($trim);
                  if(isset($pName) && $pName!==""){
                   ?>
                   
                   </tr>
                   <tr>
                        <td colspan="2" align="center">
                          <p>Add your hours for <a id='aTest'><?php echo $date; ?></a></p>
                          
                        </td>
                        <td colspan="2" align="center">
                          <a href='javascript:scwShow(scwID("aTest"),scwID("aTest"));' :mrgreen:***THIS IS WHRE THE CALENDAR IS CALLED ***:mrgreen: onclick=>Click here to change the date</a>
                        </td>
                      </tr>
                  
                  <tr>
                    <td colspan="4">
                      <table width="100%">
                        <tr>
                          <td colspan="2" height="30px">
                            Currently Select Project: <b><?php echo $pName; ?></b>
                          </td>
                        </tr>
                        <tr>
                          <td width="30%">
                            <p>Type of work</p>
                          </td>
                          <td width="30%">
                            <p>Hours</p>
                          </td>
                          <td width="40%">
                            <p>Notes</p>
                          </td>
                        </tr>
                        </form>
                        <form name="hours" method="get" action="addHoursDB.php">
                        <input type="hidden" name="date" value="bolocks">
                        <?php
:mrgreen:***this function checks to see if a record already exists for the username, date and project that are currently selected ***:mrgreen:
                          function exists(){
                            $sqlexists = "select Date from day where Username='".$_SESSION['username']."';";
                            if($existsQuery = mysql_query($sqlexists) or die("there was an error")){
                              //echo'inside if statement';
                              while($check = mysql_fetch_array($existsQuery)){
                                $datecheck = $check['Date'];
                                //echo'inside while loop';
                                if($date == $datecheck){
                                 $exists = true; 
                                 //echo'the record already exists';
                                 break;
                                }
                                else if($date !==$datecheck){
                                  $exists = false;
                                }
                              }
                            }
                            return exists;
                          }
                          if(exists()==false){
                          echo'<tr><td colspan="4">You have not added any hours for this project on this date yet, so you have been taken into the "normal mode"</td></tr>';
                            $sqlProject = "select * from project where ProjectName like '%".$pName."%';";
                            $queryProject = mysql_query($sqlProject) or die(mysql_error());
                            $workType= Array();
                            while($proj = mysql_fetch_array($queryProject)){
                              //echo'here';
                              for($r=0;$r<10;$r++){
                                //echo "WorkType: ".$proj['WorkType1'];
                                $workType[$r] = $proj['WorkType'.($r+1)];
                                if(isset($workType[$r]) && $workType[$r]!==""){
                                  echo'
                                      <tr>
                                        <td>
                                          <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
                                        </td>
                                        <td>
                                          <p>Hrs: <select name="hoursHours'.($r+1).'"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option></select> Mins: <select name="hoursMins'.($r+1).'"><option>0</option><option>15</option><option>30</option><option>45</option></select></p>
                                        </td>
                                        <td>
                                          <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
                                        </td>
                                      </tr>
                                  ';
                                }
                                else{break;}
                              }
                            }
                          }
                          else if(exists()==true){
                          echo'<tr><td colspan="4">You have already added hours for this project on this date, so you have been taken into the "amend mode"</td></tr>';
                          $_SESSION['dayexists']='true';
                            $sqlProject = "select * from day where Date='".$Date."' AND ProjectName like '%".$pName."%' AND Username='".$_SESSION['username']."';";
                            
                            $queryProject = mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
                            mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
                            $workType= Array();
                            while($proj = mysql_fetch_array($queryProject)){
                              echo'here';
                              for($r=0;$r<10;$r++){
                                //echo "WorkType: ".$proj['WorkType1'];
                                $workType[$r] = $proj['WorkType'.($r+1)];
                                if(isset($workType[$r]) && $workType[$r]!==""){
                                  echo'
                                      <tr>
                                        <td>
                                          <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
                                        </td>
                                        <td>
                                          <p>Hrs: <select name="hoursHours'.($r+1).'"><option></option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option></select> Mins: <select name="hoursMins'.($r+1).'"><option></option><option>15</option><option>30</option><option>45</option></select></p>
                                        </td>
                                        <td>
                                          <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
                                        </td>
                                      </tr>
                                  ';
                                }
                                else{break;}
                              }
                            }
                          }
                          
                          ?>
                          <tr>
                            <td>
                          <input type="hidden" name="projectName" value="<?php echo $pName; ?>"><input type="submit" value="Submit" name="submit" onclick="readDate('aTest')">
                            </td>
                          </tr>
                          </table>
                            </td>
                            </tr>     
                            </form>
                          </table>
                          <!-- end of inner content table -->
                          <?php
                          
                    }
            }
            else{echo "<tr><td>You are not logged in. Click <a href='index.php'>here</a> to log in.</td></tr>";}
            echo'
              </td>
            </tr>
        </table>
        <!-- end of content table -->
      </td></tr>
    </table>
    <!-- end of container table -->
  </body>
</html>
';
?>

The problem at the moment is becuase when the page loads it gets todays date (a date has to be supplied to the javascript calendar before you pick a different date, so i pass todays date in the url from the previous page)
So once you have added some information for a particular date with a particular username and a particular project title, the script always thinks you have already added hours for that day and goes into the "amend/edit" block of code. I need to be able to change the date using the calendar then the method exists() to be called and passed the new date (which will then mean the method wont find an existing record and will jump to the "new hours" type block)

I know this is pretty long and maybe too complex, but i have been trying to find a solution for a while now and its getting really annoying!

I hope this makes sense!

Please help!!!!!

Thanks,

Mike

The only way you can update a mysql database on the server from the browser is to send a new HTTP Request. This usually means refreshing the page, but there are a few methods that allow you to do so without refreshing the page.

1) XMLHttpRequest (AJAX)
2) by adding new <script> tags after the document has loaded
3) Frames (or Iframes)

Either way, you'll need to get the date via JavaScript, then create a new HTTP Request to your server passing the date as a parameter in the URL. The PHP page you request will then add the date to the database.

not sure why it posted my original post again, currently i am using $_GET to get today's date (which is retreived by a js function on a prev page) but then when i call the calendar the calendar js file doesnt refresh the page when it updates the date (which is where the problem lies) so i cant use $_GET at the mo to get the new date (as it wont be the new date supplied by the calendar, it will be the old date passed in the url from the prev page)

I will try to re-code other elements of my page so i can use a page refresh and get the date using the url and $_GET.

Cheers for the help, its much appreciated!!!

Mike

not sure why it posted my original post again, currently i am using $_GET to get today's date (which is retreived by a js function on a prev page) but then when i call the calendar the calendar js file doesnt refresh the page when it updates the date (which is where the problem lies) so i cant use $_GET at the mo to get the new date (as it wont be the new date supplied by the calendar, it will be the old date passed in the url from the prev page)

I will try to re-code other elements of my page so i can use a page refresh and get the date using the url and $_GET.

Cheers for the help, its much appreciated!!!

Mike

It didn't repost your original post, I just quoted your post in my reply.

The only way you can update a mysql database on the server from the browser is to send a new HTTP Request. This usually means refreshing the page, but there are a few methods that allow you to do so without refreshing the page.

1) XMLHttpRequest (AJAX)
2) by adding new <script> tags after the document has loaded
3) Frames (or Iframes)

Either way, you'll need to get the date via JavaScript, then create a new HTTP Request to your server passing the date as a parameter in the URL. The PHP page you request will then add the date to the database.

What you have to note is that when PHP executes, it executes on the server. The HTML output is then sent to the browser.
If any change is made to the HTML on the browser (like the date change using JS), PHP does not know of it. The only way you can let PHP know it to send another HTTP request back to the PHP server.
You can however make a HTTP request to the server without reloading the page.
I noted the methods above.

Here is what happens when a page loads on the browser.

Browser (HTTP Client) -> Page Request (HTTP Request) -> Server
Server (PHP Processing) -> Page Response (HTTP Response) -> Browser
JavaScript (DHTML etc.)

If you want to update something on the browser without reloading a page, you can do so like below: (this example uses xmlHTTPRequest)

Browser (HTTP Client) -> Page Request (HTTP Request) -> Server
Server (PHP Processing) -> Page Response (HTTP Response) -> Browser
JavaScript -> xmlHTTPRequest (HTTP Request) -> Server
Server (PHP Processing) -> HTTP Response -> JavaScript (Browser)

This is a very basic example.

If you want to know more about XMLHTTPRequest, try the JS forum. They should have lots of hints there.

Be a part of the DaniWeb community

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