PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/PersonalPortfolio/R1/pages/account.php

https://gitlab.com/ji5656/test2
PHP | 188 lines | 160 code | 24 blank | 4 comment | 5 complexity | f02ad60aef164a29d049602114bbe766 MD5 | raw file
  1. <?php
  2. $page = "My Account";
  3. include '../includes/connect.php';
  4. include '../includes/header.php';
  5. include '../includes/nav.php';
  6. include "../includes/loginmembercheck.php";
  7. ?>
  8. <div class="login">
  9. <?php
  10. $memberID = $_SESSION['user'];
  11. $sql = "SELECT * FROM member WHERE memberID = '$memberID'";
  12. $result = mysqli_query($con, $sql) or die(mysqli_error($con));
  13. $row = mysqli_fetch_array($result);
  14. ?>
  15. <?php
  16. if(isset($_SESSION['error']))
  17. {
  18. echo '<div class="error">';
  19. echo '<p>' . $_SESSION['error'] . '</p>';
  20. echo '</div>';
  21. unset($_SESSION['error']);
  22. }
  23. elseif(isset($_SESSION['success']))
  24. {
  25. echo '<div class="success">';
  26. echo '<p>' . $_SESSION['success'] . '</p>';
  27. echo '</div>';
  28. unset($_SESSION['success']);
  29. }
  30. ?>
  31. <div class="row">
  32. <div class="col-md-12" id = "account">
  33. <hr><h2>My Account</h1><hr>
  34. <p>Update your account details.</p>
  35. <form action="accountprocessing.php" method="post">
  36. <label>Username*</label> <input type="text" name="username" required
  37. value="<?php echo $row['username'] ?>" readonly /><br />
  38. <label>First Name*</label> <input type="text" name="firstname" required
  39. value="<?php echo $row['firstname'] ?>" /><br />
  40. <label>Last Name*</label> <input type="text" name="lastname" required
  41. value="<?php echo $row['lastname'] ?>" /><br />
  42. <label>Street number</label> <input type="text" name="streetnum" value="<?php echo
  43. $row['streetnum'] ?>"/><br />
  44. <label>Street name</label> <input type="text" name="streetname" value="<?php echo
  45. $row['streetname'] ?>"/><br />
  46. <label>Suburb</label> <input type="text" name="suburb" value="<?php echo
  47. $row['suburb'] ?>" /><br />
  48. <label>State</label>
  49. <?php
  50. $tableName='member';
  51. $colState='state';
  52. function getEnumState($tableName, $colState)
  53. {
  54. global $con;
  55. $sql = "SHOW COLUMNS FROM $tableName WHERE field='$colState'";
  56. //retrieve enum column
  57. $result = mysqli_query($con, $sql) or die(mysqli_error($con));
  58. $row = mysqli_fetch_array($result);
  59. $type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space
  60. $enumValues = substr($type, 0, -1);
  61. $enumExplode = explode(',', $enumValues);
  62. return $enumExplode;
  63. }
  64. $enumValues = getEnumState('member', 'state');
  65. echo '<select name="state">';
  66. if((is_null($row['state'])) || (empty($row['state']))) //if the state field is NULL or empty
  67. {
  68. echo "<option value=''>Please select</option>";
  69. }
  70. else
  71. {
  72. echo "<option value=" . $row['state'] . ">" . $row['state'] .
  73. "</option>"; //display the selected enum value
  74. }
  75. foreach($enumValues as $value)
  76. {
  77. echo '<option value="' . $removeQuotes = str_replace("'", "",
  78. $value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>'; //remove the quotes from the enum values
  79. }
  80. echo '</select><br />';
  81. ?>
  82. <p>&nbsp;</p>
  83. <label>Postcode*</label> <input type="text" name="postcode" required
  84. value="<?php echo $row['postcode'] ?>"/><br />
  85. <label>Country*</label> <input type="text" name="country" required
  86. value="<?php echo $row['country'] ?>"/><br />
  87. <label>Phone</label> <input type="text" name="phone" value="<?php echo
  88. $row['phone'] ?>"/><br />
  89. <label>Mobile</label> <input type="text" name="mobile" value="<?php echo
  90. $row['mobile'] ?>" /><br />
  91. <label>Email*</label> <input type="email" name="email" required
  92. value="<?php echo $row['email'] ?>" /><br />
  93. <label>Gender*</label>
  94. <?php
  95. //generate drop-down list for gender using enum data type and values from database
  96. $tableName='member';
  97. $colGender='gender';
  98. function getEnumGender($tableName, $colGender)
  99. {
  100. global $con; //enable database connection in the function
  101. $sql = "SHOW COLUMNS FROM $tableName WHERE field='$colGender'";
  102. //retrieve enum column
  103. $result = mysqli_query($con, $sql) or die(mysqli_error($con));
  104. //run the query
  105. $row = mysqli_fetch_array($result); //store the results in a variable named $row
  106. $type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space
  107. $enumValues = substr($type, 0, -1); //return the enum string
  108. $enumExplode = explode(',', $enumValues); //split the enum string into individual values
  109. return $enumExplode; //return all the enum individual values
  110. }
  111. $enumValues = getEnumGender('member', 'gender');
  112. echo '<select name="gender">';
  113. echo "<option value=" . $row['gender'] . ">" . $row['gender'] .
  114. "</option>"; //display the selected enum value
  115. foreach($enumValues as $value)
  116. {
  117. echo '<option value="' . $removeQuotes = str_replace("'", "",
  118. $value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>';
  119. }
  120. echo '</select>';
  121. ?>
  122. <input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
  123. <input type="submit" name="accountupdate" value="Update Account" />
  124. </form>
  125. <h3>Update Image</h3>
  126. <?php
  127. if((is_null($row['image'])) || (empty($row['image']))) //if the photo field is NULL or empty
  128. {
  129. echo "<p><img src='../img/member.png' width=150 height=150
  130. alt='default photo' /></p>";
  131. }
  132. else
  133. {
  134. echo "<p><img src='../img/" . ($row['image']) . "'" . '
  135. width=150 height=150 alt="contact photo"' . "/></p>";
  136. }
  137. ?>
  138. <form action="accountimageprocessing.php" method="post"
  139. enctype="multipart/form-data">
  140. <input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
  141. <label>New Image</label> <input type="file" name="image" /><br />
  142. <p>Accepted files are JPG, GIF or PNG. Maximum size is 500kb.</p>
  143. <p><input type="submit" name="imageupdate" value="Update Image" /></p>
  144. </form>
  145. <h3>Update Password</h3>
  146. <p>Passwords must have a minimum of 8 characters.</p>
  147. <form action="accountpasswordprocessing.php" method="post">
  148. <label>New Password*</label> <input type="password" name="password"
  149. pattern=".{8,}" title= "Password must be 8 characters or more" required /><br />
  150. <input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
  151. <p><input type="submit" name="passwordupdate" value="Update Password"
  152. /></p>
  153. </form>
  154. <h3>Delete My Account</h3>
  155. <p>We're sorry to hear you'd like to delete your account.<br/> By clicking the
  156. button below you will be applied to delete your accout to admin. when your account delete, confirm mail will be sent</p>
  157. <form action="accountdelete.php" method="post">
  158. <p><input type="submit" value="Delete My Account" onclick="return
  159. confirm('Are you sure you wish to permanently delete your account?');" ></p>
  160. <input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
  161. </form>
  162. </div> <!-- end #content -->
  163. </div>
  164. </div>