/www/caregiver/editChildProfileSubmit.php

https://github.com/KevinJones/Emotional-Trainer · PHP · 210 lines · 160 code · 31 blank · 19 comment · 36 complexity · f5fcf31184aaa2016f8b6afd1523f11d MD5 · raw file

  1. <?php
  2. /*
  3. Project Emotional Trainer
  4. Created by Chameleon Designs
  5. Moinak Bandyopadhyay, Jessica Blair, Kevin Jones, Mudit Manu Paliwal and Jacob Solomon.
  6. Filename: editChildProfileSubmit.php
  7. Description: This file contains the php code that runs after a caregiver makes changes to a child's profile and clicks submit.
  8. It duplicates the changes in the database.
  9. */
  10. echo 'blah'.$_COOKIE["CaregiverID"].'whoa START </html>';
  11. $caregiverID1 = 0;
  12. $childID1 =0;
  13. if (isset($_COOKIE["CaregiverID"]))
  14. {
  15. //echo 'blah'.$_COOKIE["CaregiverID"].'whoa isset Cookie </html>';
  16. $caregiverID1 = $_COOKIE["CaregiverID"];
  17. }
  18. else
  19. {
  20. echo 'blah'.$_COOKIE["CaregiverID"].'whoa2 </html>';
  21. }
  22. /*simple checking of the data*/
  23. if(isset($_POST['username']))
  24. {
  25. $username = $_POST['username'];
  26. $name = "";
  27. if (isset($_POST['realName']))
  28. {
  29. $name = $_POST['realName'];
  30. }
  31. $nameSize = strlen($name);
  32. /*Connection to database cs4911_Team46 using your login name and password*/
  33. $db=mysql_connect('localhost','cs4911_Team46','rmkU1KxJ') or die("Could not connect to Emotional Trainer Database: ". mysql_error());
  34. mysql_select_db('cs4911_Team46');
  35. $q = mysql_query("Select ChildID from Child where CaregiverID = '$caregiverID1';");
  36. if(mysql_affected_rows()>0)
  37. {
  38. $row = mysql_fetch_object($q);
  39. $expire=time()+60*60*24*30;
  40. setcookie("ChildID", $row -> ChildID, $expire);
  41. $childID1 = $_COOKIE["ChildID"];
  42. }
  43. else
  44. {
  45. $result = 'Sorry, try again ' ;
  46. echo $result;
  47. }
  48. if (isset($_FILES['element_7']) && $_FILES['element_7']['size'] > 0)
  49. {
  50. // Temporary file name stored on the server
  51. $tmpName = $_FILES['element_7']['tmp_name'];
  52. // Read the file
  53. $fp = fopen($tmpName, 'r');
  54. $data = fread($fp, filesize($tmpName));
  55. $data = addslashes($data);
  56. fclose($fp);
  57. if($caregiverID1 > 0 )
  58. {
  59. $q = mysql_query("Select ChildID from Child where CaregiverID = '$caregiverID1';");
  60. if(mysql_affected_rows()>0)
  61. {
  62. $row = mysql_fetch_object($q);
  63. $expire=time()+60*60*24*30;
  64. setcookie("ChildID", $row -> ChildID, $expire);
  65. $childID1 = $_COOKIE["ChildID"];
  66. }
  67. else
  68. {
  69. $result = 'Sorry, try again ' ;
  70. echo $result;
  71. }
  72. $query = mysql_query("UPDATE Child SET Picture ='$data' where ChildID = '$childID1';");
  73. if(mysql_affected_rows()>0)
  74. {
  75. $_SESSION['Picture'] = $data ;
  76. }
  77. else
  78. {
  79. $result = 'Sorry, try again ' ;
  80. echo $result;
  81. }
  82. }
  83. if (empty($day) && empty ($month) && empty($year))
  84. {
  85. echo 'Could not run insert query: DATE ' . mysql_error();
  86. //exit;
  87. }
  88. }
  89. if(isset($_POST['element_6_1']) && isset($_POST['element_6_2']) && isset($_POST['element_6_3']))
  90. {
  91. $day = $_POST['element_6_1'];
  92. $month = $_POST['element_6_2'];
  93. $year = $_POST['element_6_3'];
  94. $date = $year.'-'.$month.'-'.$day;
  95. if($caregiverID1 > 0 && !empty($day) && !empty ($month) && !empty($year))
  96. {
  97. $query = mysql_query("UPDATE Child SET DOB ='$date' where ChildID = '$childID1';");
  98. if(mysql_affected_rows()>0)
  99. {
  100. $_SESSION['DOB'] = $date ;
  101. }
  102. else
  103. {
  104. $result = 'Sorry, try again ' ;
  105. echo $result;
  106. }
  107. }
  108. if (empty($day) && empty ($month) && empty($year))
  109. {
  110. echo 'Could not run insert query: DATE ' . mysql_error();
  111. //exit;
  112. }
  113. }
  114. if(isset($_POST['realName']))
  115. {
  116. if($caregiverID1 >0)
  117. {
  118. $query = mysql_query("UPDATE Child SET Name ='$name' where ChildID = '$childID1';");
  119. if(mysql_affected_rows()>0)
  120. {
  121. $_SESSION['name'] = $name;
  122. }
  123. else
  124. {
  125. $result = 'Sorry, try again ' ;
  126. echo $result;
  127. }
  128. }
  129. if (!$query)
  130. {
  131. echo 'Could not run insert query: ' . mysql_error();
  132. exit;
  133. }
  134. }
  135. if(isset($_POST['email']))
  136. {
  137. if($caregiverID1 >0)
  138. {
  139. $query = mysql_query("UPDATE Child SET Email = '{$_POST['email']}' where ChildID = '$childID1';");
  140. }
  141. if (!$query)
  142. {
  143. echo 'Could not run insert query: ' . mysql_error();
  144. exit;
  145. }
  146. if(mysql_affected_rows()>0)
  147. {
  148. $_SESSION['Email'] = $_POST['email'];
  149. }
  150. else
  151. {
  152. $result = 'Sorry, try again ' ;
  153. echo $result;
  154. }
  155. }
  156. if(isset($_POST['password']))
  157. {
  158. if($caregiverID1 > 0 && !empty($_POST['password']))
  159. {
  160. $query = mysql_query("UPDATE Child SET Password=SHA1('{$_POST['password']}') where ChildID = '$childID1';");
  161. }
  162. if ( empty($_POST['password']))
  163. {
  164. echo 'Could not run insert query: PASSWORD' . mysql_error();
  165. //exit;
  166. }
  167. }
  168. header("Location: caregiverHomepage.php");
  169. mysql_close($db);
  170. }
  171. else
  172. {
  173. echo 'Not going into method';
  174. header("Location: register.php");
  175. }
  176. ?>