Guest User

Untitled

a guest
Aug 9th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. Creating an update profile page, mysqli/php
  2. <?php
  3. session_start();
  4. include("connection.php");
  5. include("function.php");
  6.  
  7. if($_SESSION['login'] != 'true'){
  8. header("location:index.php");
  9. }
  10. $id = $_SESSION['member_id'];
  11. $select = mysqli_query($dbc,"SELECT * FROM members WHERE member_id = '$id'");
  12. $object = mysqli_fetch_array($select);
  13.  
  14.  
  15. $username=$object['username'];
  16. $first=$object['firstname'];
  17. $last=$object['lastname'];
  18. $pass=$object['password'];
  19. $email=$object['email'];
  20.  
  21.  
  22.  
  23. if(isset($_POST['insert']))
  24. {
  25. $firstname = $_POST['firstname'];
  26. $lastname = $_POST['lastname'];
  27. $password = $_POST['password'];
  28. $email = $_POST['email'];
  29.  
  30.  
  31.  
  32. $sql = mysqli_query($dbc,"UPDATE members SET firstname = '$firstname', lastname = '$lastname', password = '$password', email = '$email', WHERE member_id = '$id'") or die(mysqli_error($dbc));
  33. $result = mysqli_query($dbc,$sql);
  34.  
  35. if ($result){
  36. $success = '<p style="color:blue;text-align:center;"> Records saved!</p>';
  37. }
  38. header("location:profiletest.php");
  39.  
  40.  
  41. }
  42. if(isset($_POST['Submit'])){
  43. $member_id=$_SESSION['member_id'];
  44. $name = $_FILES["image"] ["name"];
  45. $type = $_FILES["image"] ["type"];
  46. $size = $_FILES["image"] ["size"];
  47. $temp = $_FILES["image"] ["tmp_name"];
  48. $error = $_FILES["image"] ["error"];
  49. mysqli_query($dbc,"UPDATE members SET photo = '$name' WHERE member_id = '$member_id'") or die(mysqli_error($dbc));
  50.  
  51. if ($error > 0){
  52. die("Error uploading file! Code $error.");
  53. }else{
  54. if($size > 10000000) //conditions for the file
  55. {
  56. die("Format is not allowed or file size is too big!");
  57. }
  58. else
  59. {
  60. move_uploaded_file($temp,"image/members/".$name);
  61. }
  62. }
  63. }
  64.  
  65. ?>
  66.  
  67. <form name="" method="post" enctype='multipart/form-data'>
  68. <input id="browse" type="file" name="image">
  69. <input id="upload" type="submit" name="Submit"
  70. value="Change your primary picture" /> <br> <br> <br>
  71. </form> <form name="insert" method="post"><br>
  72. <p>
  73. Firstname: <input type="text" name="firstname" id="inputtype"
  74. value="<?php echo $first; ?>">
  75.  
  76. Lastname:
  77. <input type="text" name="lastname" id="inputtype"
  78. value="<?php echo $last; ?>">
  79. </p> <br>
  80. <p>
  81. Change Password: <input type="text" name="password" id="inputtype"
  82. value="<?php echo $pass; ?>">
  83. </p> <br>
  84. <p>
  85.  
  86. EmailAddress:<input type="text" name="email" id="inputtype"
  87. value="<?php echo $email; ?>">
  88. </p> <br>
  89. <p>
  90. </p>
  91. <br> <br>
  92. <p align="right"style="padding-right: 129px; width: 121px; height: 48px;">
  93. <input type="submit" id="inputsubmit" name="insert" value="Save" id="save" width="10px">
  94. </p> <br />
  95. </form>
  96. <div class="art-blockcontent-body">
  97. <h2 class="art-postheader"></h2>
  98. <div class="cleared"></div>
  99. <div>
  100. <form method='post' action='profiletest.php'></form>
  101. </div>
  102.  
  103. UPDATE members SET firstname = '$firstname', lastname = '$lastname', password = '$password', email = '$email', WHERE member_id = '$id'
Add Comment
Please, Sign In to add comment