Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. <?php
  2. //connect to database
  3. @ $db= new mysqli('localhost','root','','assignment1');
  4. if (mysqli_connect_error())
  5. {//display the details of any connection errors
  6. echo 'Error connecting to database:<br/>'.mysqli_connect_error();
  7. exit;
  8. }
  9. session_start();
  10. if ( !isset( $_SESSION['volunteermail'] ))
  11. {
  12. header('Location: login.php');
  13. exit;
  14. }
  15. //process submitted form
  16. if (isset($_POST['Address1']))
  17. {
  18. //create short variable names from the data received from the form
  19. $Address1 = $_POST['Address1'];
  20. $Address2 = $_POST['Address2'];
  21. $Suburb = $_POST['Suburb'];
  22. $Postcode = $_POST['Postcode'];
  23. $PhoneNo = $_POST['PhoneNo'];
  24. $password = $_POST['password'];
  25. $confirmPassword = $_POST['confirmPassword'];
  26.  
  27. //we create this variable and set it to an empty string... if it remains empty by the end
  28. //of our validation code, then there was no error found
  29. $error_message='';
  30. //first we'll check if any of our required fields are empty all at once
  31. if (empty($Address1)||empty($Address2)||empty($Suburb)||empty($Postcode)||empty($PhoneNo)||empty($password)||empty($confirmPassword))
  32. {
  33. $error_message='One of the required values was blank.';
  34. }
  35. //check postcode must have 4 digit only
  36. elseif (strlen($Postcode)!=4)
  37. {
  38. $error_message='Your postcode must have 4 digit';
  39. }
  40. //now we'll check if the phone number is not numberic
  41. elseif (!is_numeric($PhoneNo))
  42. {
  43. $error_message='Your phone n0 is not numberic.';
  44. }
  45. //check the phone number must have 11 digit only based on the australia phoneNo standard
  46. elseif (strlen($PhoneNo)>10)
  47. {
  48. $error_message='Your Phone Number must have 10 digit or below';
  49. }
  50. //now we'll check if the password is long enough
  51. elseif (strlen($password)<5)
  52. {
  53. $error_message='your password is not long enough, must be 5 and above';
  54. }
  55. //check confirmPassword are matching with the origin password or not
  56. elseif ($password != $confirmPassword)
  57. {
  58. $error_message='your password do not match.';
  59. }
  60.  
  61. //now we'll check if the email address already exists in the database
  62. //$email_query= "SELECT email FROM volunteers WHERE email='".$emailaddress."' AND vol_time_id !=" .$_GET['edit_mailid'];
  63. //$email_results=$db->query($email_query);
  64.  
  65. //if ($email_results-> num_rows > 0)
  66. //{
  67. // $error_message='Your email address already exist, choose another.';
  68.  
  69. //}
  70.  
  71.  
  72.  
  73. //if the error message variable is not empty(i.e. an error has been found)
  74. if($error_message!='')
  75. {
  76. //we'll just provide the user with the error message and a back link if there is an error
  77. //the exit command tells the server/PHP to stop processing the script at that point
  78. echo 'error:'.$error_message.'<a href="javascript: history.back();">go back</a>.';
  79. echo '</body></html>';
  80. exit;
  81. }
  82. else
  83. {
  84. $query = "UPDATE volunteers SET Address1='".$Address1."', Address2='".$Address2."', Suburb='".$Suburb."',Postcode='".$Postcode."',
  85. PhoneNo='".$PhoneNo."',password='".$password."',confirmPassword='".$confirmPassword."'";
  86.  
  87.  
  88. $result= $db->query($query);
  89.  
  90. if ($result)
  91. {
  92. echo'<p>User details inserted into database!</p>';
  93. }
  94. else
  95. {
  96. echo'<p>Error updating details. Error message:</p>';
  97. echo '<p>'.$db->error.'</p>';
  98. }
  99.  
  100. }
  101. }
  102.  
  103. //fetch the user's details and store them in $rows
  104. $query= 'SELECT * FROM volunteers WHERE email= "'. $_SESSION['volunteermail'].'"' ;
  105. $result = $db->query($query);
  106. $row=$result->fetch_assoc();
  107.  
  108.  
  109. ?>
  110. <!DOCTYPE html>
  111. <html>
  112. <head>
  113. <title>Edit User Form</title>
  114. </head>
  115.  
  116. <body>
  117. <h2><strong>User Details</strong></h2>
  118. <form name="EditUserForm" method="post" action="editUsers.php">
  119. <table style="width: 500px; border: 0px;" cellspacing="1" cellpadding="1">
  120. <tr>
  121. <td colspan="2"><strong>Personal Details</strong></td>
  122. </tr>
  123. <tr style="background-color: #FFFFFF;">
  124. <td>Address1</td>
  125. <td>
  126.  
  127. <textarea name="Address1" cols="30" rows="3">
  128.  
  129. <?php echo $row['address_In_1'] ?>
  130. </textarea>*</td>
  131. </tr>
  132. <tr style="background-color: #FFFFFF;">
  133. <td>Address2</td>
  134. <td>
  135. <textarea name="Address2" cols="30" rows="3">
  136.  
  137. <?php echo $row['address_In_2'] ?>
  138. </textarea>
  139.  
  140.  
  141. </td>
  142. </tr>
  143. <tr style="background-color: #FFFFFF;">
  144. <td>Suburb</td>
  145. <td>
  146. <input value = <?php echo $row['suburb'] ?> name="Suburb" type="text" style="width: 200px;" maxlength="100" />*</td>
  147. </tr><tr style="background-color: #FFFFFF;">
  148. <td>Postcode</td>
  149. <td>
  150. <input value = <?php echo $row['postcode'] ?> name="Postcode" type="text" style="width: 200px;" maxlength="100" />*</td>
  151. </tr>
  152. <tr style="background-color: #FFFFFF;">
  153. <td>PhoneNo</td>
  154. <td>
  155. <input value = <?php echo $row['PhoneNo'] ?> name="PhoneNo" type="text" style="width: 150px;" maxlength="15" />*</td>
  156. </tr>
  157. <tr>
  158. <td colspan="2">&nbsp;</td>
  159. </tr>
  160. <tr style="background-color: #FFFFFF;">
  161. <td>Password</td>
  162. <td>
  163. <input value = <?php echo $row['Password'] ?> name="password" type="password" style="width: 200px;" maxlength="20" />*</td>
  164. </tr>
  165. <tr style="background-color: #FFFFFF;">
  166. <td>Confirm Password</td>
  167. <td>
  168. <input value = <?php echo $row['Confirm_password'] ?> name="confirmPassword" type="password" style="width: 200px;" maxlength="20" />*</td>
  169. </tr>
  170. <tr>
  171. <td colspan="2">&nbsp;</td>
  172. </tr>
  173. <tr style="background-color: #FFFFFF;">
  174. <td>
  175. <input type="reset" name="reset" value="Reset" />
  176. <input type="submit" name="submit" value="Submit" /></td>
  177. <td>
  178. <div align="right">* indicates required field</div></td>
  179. </tr>
  180. </table>
  181. </form>
  182. </body>
  183. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement