moizbaloch

myCode

Aug 6th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['button'])) {
  3.  
  4. $imgFile = $_FILES['img']['name'];
  5. $tmp_dir = $_FILES['img']['tmp_name'];
  6. $imgSize = $_FILES['img']['size'];
  7.  
  8. if(!empty($imgFile))
  9. {
  10.  
  11. $upload_dir = 'images/'; // upload directory
  12.  
  13. $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
  14.  
  15. // valid image extensions
  16. $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  17.  
  18. // rename uploading image
  19. $coverpic = rand(1000,1000000).".".$imgExt;
  20. $deat = $upload_dir.'/'.$coverpic;
  21. // allow valid image file formats
  22. if(in_array($imgExt, $valid_extensions)){
  23. // Check file size ‘5MB’
  24. if($imgSize < 5000000) {
  25. move_uploaded_file($tmp_dir,$upload_dir.$coverpic);
  26. }
  27. else{
  28. $errMSG = "Sorry, your file is too large.";
  29. }
  30. }
  31. }//empty if end
  32.  
  33. else{
  34. $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  35. }
  36.  
  37. $dbhost = 'localhost';
  38. $dbuser = 'root';
  39. $dbpass = '';
  40.  
  41. $conn = mysql_connect($dbhost,$dbuser,$dbpass);
  42.  
  43. if(!$conn ) {
  44. die('Could not connect:'.mysql_error());
  45. }
  46.  
  47. mysql_select_db('jamesthew');
  48. $u_name = $_POST['name'];
  49. $usr_name = $_POST['username'];
  50. $u_pass = $_POST['password'];
  51. $u_age = $_POST['age'];
  52. $u_gender = $_POST['gender'];
  53. $u_email = $_POST['email'];
  54.  
  55. $usrid=$_SESSION['uid'];
  56. if(!empty($imgFile)):
  57. $sqlt="UPDATE owner SET name = '$u_name',username = '$usr_name',password='$u_pass',image='$deat',age='$u_age',gender='$u_gender',email='$u_email' WHERE id='$usrid'";
  58.  
  59. $retval = mysql_query( $sqlt, $conn );
  60.  
  61. if(! $retval ) {
  62. die('Could not update data: ' . mysql_error());
  63. }
  64. echo '<div class="alert alert-success">Updated data successfully </div>';
  65.  
  66. else:
  67. $sqlt="UPDATE owner SET name = '$u_name',username = '$usr_name',password='$u_pass',age='$u_age',gender='$u_gender',email='$u_email' WHERE id='$usrid'";
  68.  
  69. $retval = mysql_query( $sqlt, $conn );
  70.  
  71. if(! $retval ) {
  72. die('Could not update data: ' . mysql_error());
  73. }
  74. echo '<div class="alert alert-success">Updated data successfully </div>';
  75. //header("Refresh: 2; URL=index.php");
  76. endif;
  77. mysql_close($conn);
  78. }else {
  79. ?>
  80.  
  81. <form class="form-inline" method="POST" action="" enctype="multipart/form-data">
  82. <div class="form-group">
  83. <label for="name">Name:</label>
  84. <input type="text" class="form-control" id="name" name="name" value="<?php echo $uname?>" placeholder="Your Name">
  85. </div>
  86.  
  87. <div class="form-group">
  88. <label for="username">Username:</label>
  89. <input type="text" class="form-control" id="username" name="username" value="<?php echo $usrname?>" placeholder="Your Username">
  90. </div>
  91. <hr>
  92. <div class="form-group">
  93. <label for="password">Password:</label>
  94. <input type="text" class="form-control" id="password" name="password" value="<?php echo $usrpass?>" placeholder="Your Password">
  95. </div>
  96.  
  97. <div class="form-group">
  98. <label for="email">Email:</label>
  99. <input type="email" class="form-control" id="email" name="email" value="<?php echo $usremail?>" placeholder="Your Password">
  100. </div>
  101. <hr>
  102. <div class="form-group">
  103. <label for="email">Gender:</label>
  104. <input type="text" class="form-control" id="gender" name="gender" value="<?php echo $usrgender?>" placeholder="Your Password">
  105. </div>
  106.  
  107. <div class="form-group">
  108. <label for="age">Age:</label>
  109. <input type="text" class="form-control" id="age" name="age" value="<?php echo $usrage?>" placeholder="Your Password">
  110. </div>
  111. <hr>
  112. <div class="form-group">
  113. <label for="img">Image:</label>
  114. <input type="file" accept="image/*" class="form-control" id="img" name="img" placeholder="Your Image">
  115. </div>
  116.  
  117. <p style="color:white;">----------</p>
  118. <button type="submit" name="button" class="btn btn-warning">Update Details</button>
  119. </form>
  120.  
  121. <?php
  122. }
  123. ?>
  124. </div>
  125. <div class="modal-footer">
  126. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  127. </div>
  128. </div>
  129.  
  130. </div>
Add Comment
Please, Sign In to add comment