By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

Change database from mysql 4 to mysql 5 affects my calendar event page

P: n/a
I changed my database from mysql 4.1.10 to mysql 5.0 and I encountered error in my calendar event page. The output of my calendar date was change instead of date it becomes “>” and also when I press the button to move to another month I can’t move to another month. I have no idea why it happened.
Here is the old calendar code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $dbCnx = @mysql_connect("localhost","", "") or die('Could not Connect to the database')
  3.     mysql_select_db("mydb");    
  4. ?>
  5. <html>
  6. <script>
  7. function goLastMonth(month, year){
  8. if(month == 1){
  9. --year;
  10. month = 13;
  11. }
  12. document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month-1)+'&year='+year;
  13. }
  14. function goNextMonth(month, year){
  15. if(month == 12){
  16. ++year;
  17. month = 0;
  18. }
  19. document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month+1)+'&year='+year;
  20. function remChars(txtControl, txtCount, intMaxLength)
  21. {
  22. if(txtControl.value.length > intMaxLength)
  23. txtControl.value = txtControl.value.substring(0, (intMaxLength-1));
  24. else
  25. txtCount.value = intMaxLength - txtControl.value.length;
  26. }
  27. function checkFilled() {
  28. var filled = 0
  29. var x = document.form1.calName.value;
  30. if (x.length > 0) {filled ++}
  31. var y = document.form1.calDesc.value;
  32. if (y.length > 0) {filled ++}
  33. if (filled == 2) {
  34. document.getElementById("Submit").disabled = false;
  35. }
  36. else {document.getElementById("Submit").disabled = true} // in case a field is filled then erased
  37. }
  38. </script>
  39. <body>
  40. <?php
  41. $day = (isset($_GET["day"])) ? $_GET['day'] : "";
  42. $month = (isset($_GET["month"])) ? $_GET['month'] : "";
  43. $year = (isset($_GET["year"])) ? $_GET['year'] : "";
  44. if(empty($day)){ $day = date("j"); }
  45. if(empty($month)){ $month = date("n"); }
  46. if(empty($year)){ $year = date("Y"); } 
  47. $currentTimeStamp = strtotime("$year-$month-$day");
  48. $monthName = date("F", $currentTimeStamp);
  49. $numDays = date("t", $currentTimeStamp);
  50. $counter = 0;
  51. function hiLightEvt($eMonth,$eDay,$eYear){
  52. $todaysDate = date("n/j/Y");
  53. $dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear;
  54. if($todaysDate == $dateToCompare){
  55. $aClass='class="today"';
  56. }else{
  57. $sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'";
  58. $result = mysql_query($sql);
  59. while($row= mysql_fetch_array($result)){
  60. if($row['eCount'] >=1){
  61. $aClass = 'class="event"';
  62. }elseif($row['eCount'] ==0){
  63. $aClass ='class="normal"';
  64. }
  65. }
  66. }
  67. return $aClass;
  68. }
  69. ?>
  70. <div id="Calendar_Event">
  71. <table width="350" cellpadding="0" cellspacing="0">
  72. <tr>
  73. <td width="50" colspan="1">
  74. <input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);">
  75. </td>
  76. <td width="250" colspan="5">
  77. <span class="title" style="color:#FFFFFF"><?php echo $monthName . " " . $year; ?></span><br>
  78. </td>
  79. <td width="50" colspan="1" align="right">
  80. <input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);">
  81. </td>
  82. </tr> 
  83. <tr>
  84. <th>M</td>
  85. <th>T</td>
  86. <th>W</td>
  87. <th>T</td>
  88. <th>F</td>
  89. <th>S</td>
  90. <th>S</td>
  91. </tr>
  92. <tr>
  93. <?php
  94. for($i = 1; $i < $numDays+1; $i++, $counter++){
  95. $dateToCompare = $month . '/' . $i . '/' . $year;
  96. $timeStamp = strtotime("$year-$month-$i");
  97. if($i == 1){
  98. $firstDay = date("N", $timeStamp);
  99. for($j = 1; $j < $firstDay; $j++, $counter++){
  100. echo "<td>&nbsp;</td>";
  101. }
  102. if($counter % 7 == 0 ){
  103. ?>
  104. </tr><tr>
  105. <?php
  106. }
  107. ?>
  108. <!--right here--><td width="50" <?=hiLightEvt($month,$i,$year);?>><a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$i;?></a></td> 
  109. <?php
  110. }
  111. ?>
  112. </table>
  113. </div>
  114. <div id="New_Event">
  115. <?php
  116. if(isset($_GET['v'])){
  117. if(isset($_POST['Submit'])){
  118. $sql="insert into calTbl(calName,calDesc,calDate,calStamp) values('" . $_POST['calName'] ."','" . $_POST['calDesc'] . "','" . $_POST['calDate'] . "',now())";
  119. mysql_query($sql);
  120. }
  121. $sql="select calName,calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'";
  122. $result = mysql_query($sql);
  123. $numRows = mysql_num_rows($result);
  124. if ($_SESSION['username']=="user1") 
  125. $check1=mysql_query("SELECT * FROM tbllogin WHERE Username='user1' AND Department='Staff' AND Permission='True'"); 
  126. $check2 = mysql_fetch_array($check1); 
  127. $username = $check2['Username']; 
  128. $dep = $check2['Department']; 
  129. $permiss = $check2['Permission']; 
  130. if($username=="user1" && $dep=="Staff" && $permiss=="True"){ 
  131. $_SESSION['isallowed'] = $check2['Permission']; 
  132. ?> 
  133. <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">Add Even</a><a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">t</a>
  134. <?php  
  135. }
  136. else 
  137. { echo "You cannot Add New Event"; } 
  138. ?>
  139. </div>
  140. <div id="Cal_Event">
  141. <?php
  142. if(isset($_GET['f'])){
  143. include 'calform.php';
  144. }
  145. if($numRows == 0 ){
  146. echo '';
  147. }else{
  148. echo '<h3>Event Listed</h3>';
  149. while($row = mysql_fetch_array($result)){
  150. ?>
  151. <h5><?=$row['calName'];?></h5>
  152. <?=$row['calDesc'];?><br/>
  153. Listed On: <?=$row['calStamp'];?>
  154. <?php
  155. }
  156. }
  157. }
  158. ?>
  159. </div>
  160. </body>
  161. </html>
  162.  
On my new codes I only change the codes for the connection of database like the “host”, ”username”, ”password”, ”database name”, “table name”.
Honestly, I have no idea why it happened after I change my database. Actually my tbluser was work so I connected in my database on my other webpage.
Any help is highly appreciated. Thank you in advance.
Oct 20 '10 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
what datatype is the `calDate` field in the new DB?
Oct 20 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.