943,746 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 50863
  • PHP RSS
Apr 12th, 2007
0

get html element value using php

Expand Post »
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 ['date']. 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 Syntax (Toggle Plain Text)
  1. <?php
  2. ob_start();
  3. session_start();
  4.  
  5. $connect = mysql_connect('localhost', 'root', '');
  6. if(!$connect){
  7. die("sql connection error");
  8. }
  9. $username = $_SESSION['username'];
  10. mysql_select_db('timesheet');
  11. $sqlUser = "select * from user where Username='".$_SESSION['username']."';";
  12. $queryUser = mysql_query($sqlUser);
  13.  
  14. ?>
  15. <html>
  16. <head>
  17. <title>Impetus online project timesheet</title>
  18. <link href="style.css" rel="stylesheet" type="text/css" />
  19. <script>
  20. function readDate(elem){
  21. var ele = document.getElementById(elem);
  22. var childNodes = ele.childNodes[0];
  23. var element = childNodes.nodeValue
  24. document.hours.date.value=element;
  25. }
  26.  
  27. function getDate(){
  28. var todaysDate;
  29. var currentTime = new Date();
  30. var day = currentTime.getDate();
  31. var month = currentTime.getMonth()+1;
  32. var year = currentTime.getFullYear();
  33. todaysDate= window.location ="addHours.php?date="+day+"/"+month+"/"+year;
  34. return todaysDate;
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <script type='text/JavaScript' src='scw.js'></script>
  40. <!-- start of container table -->
  41. <table class="tablestyle" width="800px" align="center" border="1">
  42. <tr>
  43. <td align="center" class="cellstyle"><img src="img/impetuslogo.png"></td>
  44. </tr>
  45. <tr><td class="cellstyle">
  46. <!-- start of content table -->
  47. <table align="center" width="100%" border="0">
  48. <tr>
  49. <td align="center" colspan="2"><h1>Welcome to the Impetus Online Timesheet</h1></td>
  50. </tr>
  51.  
  52. <tr>
  53. <td rowspan="5" width="20%" class="tablestyle1" valign="top">
  54. <!-- start of nav table -->
  55. <table width="100%">
  56.  
  57. <?php if(isset($_SESSION['username'])){?>
  58. <tr>
  59. <td class="cellstyle1" align="center">
  60. <?php
  61. echo 'Hello '.$username;
  62. ?>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td align="center" class="cellstyle1">
  67. <a href="yourProjects.php">Your Projects</a>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td align="center" class="cellstyle1">
  72. <a href="#">Your Hours</a>
  73. </td>
  74. </tr>
  75. <tr>
  76. <td align="center" class="cellstyle1">
  77. <a onclick="return getDate();" href="#">Add Hours</a>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td align="center" class="cellstyle1">
  82. <a href="#">Create a Report</a>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td align="center" class="cellstyle1">
  87. <a href="addProject.php">Add a new Project</a>
  88. </td>
  89. </tr>
  90. </table>
  91. <!-- end of nav table -->
  92. </td>
  93. <td class="tablestyle1">
  94. <!-- start of inner content table -->
  95. <table width="100%" border="0">
  96. <tr>
  97. <td colspan="4">
  98. <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>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td></td>
  103. </tr>
  104. <tr>
  105. <td width="10%">
  106. <p><b>Project:</b></p>
  107. </td>
  108. <form name="projName" action="addHours.php" method="get">
  109. <input type="hidden" id="hiddendate" name="hiddendate">
  110. <?php
  111. $projectName= Array();
  112. $counter=0;
  113. $date=$_GET['date'];
  114. while($row = mysql_fetch_array($queryUser)) {
  115. for($i=0;$i<15;$i++){
  116. $projectName[$i] = $row['Project'.($i+1)];
  117. if($projectName[$i]!=="" && isset($projectName[$i])){
  118. if($counter>=3){
  119. echo'
  120. </tr><tr><td></td>
  121. <td>
  122. <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
  123. </td>
  124. ';
  125. $counter=0;
  126. }
  127. else if($counter<3){
  128. echo'
  129. <td>
  130. <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
  131. </td>
  132. ';
  133. $counter++;
  134. }
  135. }
  136. //else{echo'empty';}
  137. }
  138. }
  139. $explodedGet = explode("%20", $_GET['projectName']);
  140. for($t=0;$t<count($explodedGet);$t++){
  141. $trim= $trim.$explodedGet[$t]." ";
  142. }
  143. $pName= rtrim($trim);
  144. if(isset($pName) && $pName!==""){
  145. ?>
  146.  
  147. </tr>
  148. <tr>
  149. <td colspan="2" align="center">
  150. <p>Add your hours for <a id='aTest'><?php echo $date; ?></a></p>
  151.  
  152. </td>
  153. <td colspan="2" align="center">
  154. <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>
  155. </td>
  156. </tr>
  157.  
  158. <tr>
  159. <td colspan="4">
  160. <table width="100%">
  161. <tr>
  162. <td colspan="2" height="30px">
  163. Currently Select Project: <b><?php echo $pName; ?></b>
  164. </td>
  165. </tr>
  166. <tr>
  167. <td width="30%">
  168. <p>Type of work</p>
  169. </td>
  170. <td width="30%">
  171. <p>Hours</p>
  172. </td>
  173. <td width="40%">
  174. <p>Notes</p>
  175. </td>
  176. </tr>
  177. </form>
  178. <form name="hours" method="get" action="addHoursDB.php">
  179. <input type="hidden" name="date" value="bolocks">
  180. <?php
  181. :mrgreen:***this function checks to see if a record already exists for the username, date and project that are currently selected ***:mrgreen:
  182. function exists(){
  183. $sqlexists = "select Date from day where Username='".$_SESSION['username']."';";
  184. if($existsQuery = mysql_query($sqlexists) or die("there was an error")){
  185. //echo'inside if statement';
  186. while($check = mysql_fetch_array($existsQuery)){
  187. $datecheck = $check['Date'];
  188. //echo'inside while loop';
  189. if($date == $datecheck){
  190. $exists = true;
  191. //echo'the record already exists';
  192. break;
  193. }
  194. else if($date !==$datecheck){
  195. $exists = false;
  196. }
  197. }
  198. }
  199. return exists;
  200. }
  201. if(exists()==false){
  202. 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>';
  203. $sqlProject = "select * from project where ProjectName like '%".$pName."%';";
  204. $queryProject = mysql_query($sqlProject) or die(mysql_error());
  205. $workType= Array();
  206. while($proj = mysql_fetch_array($queryProject)){
  207. //echo'here';
  208. for($r=0;$r<10;$r++){
  209. //echo "WorkType: ".$proj['WorkType1'];
  210. $workType[$r] = $proj['WorkType'.($r+1)];
  211. if(isset($workType[$r]) && $workType[$r]!==""){
  212. echo'
  213. <tr>
  214. <td>
  215. <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
  216. </td>
  217. <td>
  218. <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>
  219. </td>
  220. <td>
  221. <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
  222. </td>
  223. </tr>
  224. ';
  225. }
  226. else{break;}
  227. }
  228. }
  229. }
  230. else if(exists()==true){
  231. 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>';
  232. $_SESSION['dayexists']='true';
  233. $sqlProject = "select * from day where Date='".$Date."' AND ProjectName like '%".$pName."%' AND Username='".$_SESSION['username']."';";
  234.  
  235. $queryProject = mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
  236. mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
  237. $workType= Array();
  238. while($proj = mysql_fetch_array($queryProject)){
  239. echo'here';
  240. for($r=0;$r<10;$r++){
  241. //echo "WorkType: ".$proj['WorkType1'];
  242. $workType[$r] = $proj['WorkType'.($r+1)];
  243. if(isset($workType[$r]) && $workType[$r]!==""){
  244. echo'
  245. <tr>
  246. <td>
  247. <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
  248. </td>
  249. <td>
  250. <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>
  251. </td>
  252. <td>
  253. <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
  254. </td>
  255. </tr>
  256. ';
  257. }
  258. else{break;}
  259. }
  260. }
  261. }
  262.  
  263. ?>
  264. <tr>
  265. <td>
  266. <input type="hidden" name="projectName" value="<?php echo $pName; ?>"><input type="submit" value="Submit" name="submit" onclick="readDate('aTest')">
  267. </td>
  268. </tr>
  269. </table>
  270. </td>
  271. </tr>
  272. </form>
  273. </table>
  274. <!-- end of inner content table -->
  275. <?php
  276.  
  277. }
  278. }
  279. else{echo "<tr><td>You are not logged in. Click <a href='index.php'>here</a> to log in.</td></tr>";}
  280. echo'
  281. </td>
  282. </tr>
  283. </table>
  284. <!-- end of content table -->
  285. </td></tr>
  286. </table>
  287. <!-- end of container table -->
  288. </body>
  289. </html>
  290. ';
  291. ?>

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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikesowerbutts is offline Offline
24 posts
since Jan 2007
Apr 13th, 2007
0

Re: get html element value using php

Hi!

Have you tried using $_REQUEST['date'] as the new date seems to be placed in the address bar. PHP should read it from there.
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006
Apr 14th, 2007
0

Re: get html element value using php

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 ['date']. 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 Syntax (Toggle Plain Text)
  1. <?php
  2. ob_start();
  3. session_start();
  4.  
  5. $connect = mysql_connect('localhost', 'root', '');
  6. if(!$connect){
  7. die("sql connection error");
  8. }
  9. $username = $_SESSION['username'];
  10. mysql_select_db('timesheet');
  11. $sqlUser = "select * from user where Username='".$_SESSION['username']."';";
  12. $queryUser = mysql_query($sqlUser);
  13.  
  14. ?>
  15. <html>
  16. <head>
  17. <title>Impetus online project timesheet</title>
  18. <link href="style.css" rel="stylesheet" type="text/css" />
  19. <script>
  20. function readDate(elem){
  21. var ele = document.getElementById(elem);
  22. var childNodes = ele.childNodes[0];
  23. var element = childNodes.nodeValue
  24. document.hours.date.value=element;
  25. }
  26.  
  27. function getDate(){
  28. var todaysDate;
  29. var currentTime = new Date();
  30. var day = currentTime.getDate();
  31. var month = currentTime.getMonth()+1;
  32. var year = currentTime.getFullYear();
  33. todaysDate= window.location ="addHours.php?date="+day+"/"+month+"/"+year;
  34. return todaysDate;
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <script type='text/JavaScript' src='scw.js'></script>
  40. <!-- start of container table -->
  41. <table class="tablestyle" width="800px" align="center" border="1">
  42. <tr>
  43. <td align="center" class="cellstyle"><img src="img/impetuslogo.png"></td>
  44. </tr>
  45. <tr><td class="cellstyle">
  46. <!-- start of content table -->
  47. <table align="center" width="100%" border="0">
  48. <tr>
  49. <td align="center" colspan="2"><h1>Welcome to the Impetus Online Timesheet</h1></td>
  50. </tr>
  51.  
  52. <tr>
  53. <td rowspan="5" width="20%" class="tablestyle1" valign="top">
  54. <!-- start of nav table -->
  55. <table width="100%">
  56.  
  57. <?php if(isset($_SESSION['username'])){?>
  58. <tr>
  59. <td class="cellstyle1" align="center">
  60. <?php
  61. echo 'Hello '.$username;
  62. ?>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td align="center" class="cellstyle1">
  67. <a href="yourProjects.php">Your Projects</a>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td align="center" class="cellstyle1">
  72. <a href="#">Your Hours</a>
  73. </td>
  74. </tr>
  75. <tr>
  76. <td align="center" class="cellstyle1">
  77. <a onclick="return getDate();" href="#">Add Hours</a>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td align="center" class="cellstyle1">
  82. <a href="#">Create a Report</a>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td align="center" class="cellstyle1">
  87. <a href="addProject.php">Add a new Project</a>
  88. </td>
  89. </tr>
  90. </table>
  91. <!-- end of nav table -->
  92. </td>
  93. <td class="tablestyle1">
  94. <!-- start of inner content table -->
  95. <table width="100%" border="0">
  96. <tr>
  97. <td colspan="4">
  98. <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>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td></td>
  103. </tr>
  104. <tr>
  105. <td width="10%">
  106. <p><b>Project:</b></p>
  107. </td>
  108. <form name="projName" action="addHours.php" method="get">
  109. <input type="hidden" id="hiddendate" name="hiddendate">
  110. <?php
  111. $projectName= Array();
  112. $counter=0;
  113. $date=$_GET['date'];
  114. while($row = mysql_fetch_array($queryUser)) {
  115. for($i=0;$i<15;$i++){
  116. $projectName[$i] = $row['Project'.($i+1)];
  117. if($projectName[$i]!=="" && isset($projectName[$i])){
  118. if($counter>=3){
  119. echo'
  120. </tr><tr><td></td>
  121. <td>
  122. <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
  123. </td>
  124. ';
  125. $counter=0;
  126. }
  127. else if($counter<3){
  128. echo'
  129. <td>
  130. <a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
  131. </td>
  132. ';
  133. $counter++;
  134. }
  135. }
  136. //else{echo'empty';}
  137. }
  138. }
  139. $explodedGet = explode("%20", $_GET['projectName']);
  140. for($t=0;$t<count($explodedGet);$t++){
  141. $trim= $trim.$explodedGet[$t]." ";
  142. }
  143. $pName= rtrim($trim);
  144. if(isset($pName) && $pName!==""){
  145. ?>
  146.  
  147. </tr>
  148. <tr>
  149. <td colspan="2" align="center">
  150. <p>Add your hours for <a id='aTest'><?php echo $date; ?></a></p>
  151.  
  152. </td>
  153. <td colspan="2" align="center">
  154. <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>
  155. </td>
  156. </tr>
  157.  
  158. <tr>
  159. <td colspan="4">
  160. <table width="100%">
  161. <tr>
  162. <td colspan="2" height="30px">
  163. Currently Select Project: <b><?php echo $pName; ?></b>
  164. </td>
  165. </tr>
  166. <tr>
  167. <td width="30%">
  168. <p>Type of work</p>
  169. </td>
  170. <td width="30%">
  171. <p>Hours</p>
  172. </td>
  173. <td width="40%">
  174. <p>Notes</p>
  175. </td>
  176. </tr>
  177. </form>
  178. <form name="hours" method="get" action="addHoursDB.php">
  179. <input type="hidden" name="date" value="bolocks">
  180. <?php
  181. :mrgreen:***this function checks to see if a record already exists for the username, date and project that are currently selected ***:mrgreen:
  182. function exists(){
  183. $sqlexists = "select Date from day where Username='".$_SESSION['username']."';";
  184. if($existsQuery = mysql_query($sqlexists) or die("there was an error")){
  185. //echo'inside if statement';
  186. while($check = mysql_fetch_array($existsQuery)){
  187. $datecheck = $check['Date'];
  188. //echo'inside while loop';
  189. if($date == $datecheck){
  190. $exists = true;
  191. //echo'the record already exists';
  192. break;
  193. }
  194. else if($date !==$datecheck){
  195. $exists = false;
  196. }
  197. }
  198. }
  199. return exists;
  200. }
  201. if(exists()==false){
  202. 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>';
  203. $sqlProject = "select * from project where ProjectName like '%".$pName."%';";
  204. $queryProject = mysql_query($sqlProject) or die(mysql_error());
  205. $workType= Array();
  206. while($proj = mysql_fetch_array($queryProject)){
  207. //echo'here';
  208. for($r=0;$r<10;$r++){
  209. //echo "WorkType: ".$proj['WorkType1'];
  210. $workType[$r] = $proj['WorkType'.($r+1)];
  211. if(isset($workType[$r]) && $workType[$r]!==""){
  212. echo'
  213. <tr>
  214. <td>
  215. <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
  216. </td>
  217. <td>
  218. <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>
  219. </td>
  220. <td>
  221. <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
  222. </td>
  223. </tr>
  224. ';
  225. }
  226. else{break;}
  227. }
  228. }
  229. }
  230. else if(exists()==true){
  231. 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>';
  232. $_SESSION['dayexists']='true';
  233. $sqlProject = "select * from day where Date='".$Date."' AND ProjectName like '%".$pName."%' AND Username='".$_SESSION['username']."';";
  234.  
  235. $queryProject = mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
  236. mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
  237. $workType= Array();
  238. while($proj = mysql_fetch_array($queryProject)){
  239. echo'here';
  240. for($r=0;$r<10;$r++){
  241. //echo "WorkType: ".$proj['WorkType1'];
  242. $workType[$r] = $proj['WorkType'.($r+1)];
  243. if(isset($workType[$r]) && $workType[$r]!==""){
  244. echo'
  245. <tr>
  246. <td>
  247. <p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
  248. </td>
  249. <td>
  250. <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>
  251. </td>
  252. <td>
  253. <p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
  254. </td>
  255. </tr>
  256. ';
  257. }
  258. else{break;}
  259. }
  260. }
  261. }
  262.  
  263. ?>
  264. <tr>
  265. <td>
  266. <input type="hidden" name="projectName" value="<?php echo $pName; ?>"><input type="submit" value="Submit" name="submit" onclick="readDate('aTest')">
  267. </td>
  268. </tr>
  269. </table>
  270. </td>
  271. </tr>
  272. </form>
  273. </table>
  274. <!-- end of inner content table -->
  275. <?php
  276.  
  277. }
  278. }
  279. else{echo "<tr><td>You are not logged in. Click <a href='index.php'>here</a> to log in.</td></tr>";}
  280. echo'
  281. </td>
  282. </tr>
  283. </table>
  284. <!-- end of content table -->
  285. </td></tr>
  286. </table>
  287. <!-- end of container table -->
  288. </body>
  289. </html>
  290. ';
  291. ?>

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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Apr 16th, 2007
0

Re: get html element value using php

not sure why it posted my original post again, currently i am using $_GET['date'] 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikesowerbutts is offline Offline
24 posts
since Jan 2007
Apr 16th, 2007
0

Re: get html element value using php

not sure why it posted my original post again, currently i am using $_GET['date'] 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.

Quote ...
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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: What does the go-pear.phar file do.
Next Thread in PHP Forum Timeline: PHP Quote form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC