A unf. social network done poorly.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.7KB

  1. <?php // update-profile.php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/session.php');
  5. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/config.php');
  6. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/user-data.php');
  7. /*
  8. Note: This is a pretty big file, and could get bigger. Don't worry too much about the size, I want
  9. us to make sure this thing is functional, and quick as possible. Feel free to edit and make
  10. things faster. Unit testing goes a long way. -- Ashton
  11. */
  12. $connection = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
  13. $data = mysqli_query($connection, "SELECT * FROM users WHERE email='$email'");
  14. $bio = (!empty($_POST['bio'])) ? $_POST['bio'] : false;
  15. $country = (!empty($_POST['country'])) ? $_POST['country'] : false;
  16. $state = (!empty($_POST['state'])) ? $_POST['state'] : false;
  17. $town = (!empty($_POST['town'])) ? $_POST['town'] : false;
  18. $bio = mysqli_real_escape_string($connection, $bio);
  19. $country = mysqli_real_escape_string($connection, $country);
  20. $state = mysqli_real_escape_string($connection, $state);
  21. $town = mysqli_real_escape_string($connection, $town);
  22. /*---- Picture Update -----*/
  23. $file_name = $_FILES["DefaultPicture"]["name"];
  24. $file_ext = pathinfo($file_name);
  25. $new_file_name = $user_id.'.'.$file_ext['extension'];
  26. $file_path = $_SERVER['DOCUMENT_ROOT'] . '/socialtune/user-images/';
  27. if(!empty($file_name)){ // checks if file is actually being uploaded.
  28. if(is_dir($file_path)){ // checks if the DIR actually exists.
  29. if(is_writable($file_path)){ // Checks if the DIR can be written to.
  30. $uploaded = move_uploaded_file($_FILES['DefaultPicture']['tmp_name'], $file_path.$new_file_name);
  31. if($uploaded){
  32. echo 'File uploaded<br><br>';
  33. }else{
  34. echo 'File was not uploaded.';
  35. }
  36. }else{
  37. echo 'Upload DIR is not writable....But hey, at least it exists!';
  38. }
  39. }else{
  40. echo 'Upload DIR does not exist.<br /><br />';
  41. }
  42. }else{
  43. echo 'err...empty file... :|';
  44. }
  45. if(!$connection){
  46. due("SOMETHING WENT HORRIBLY WRONG. RUN AWAY. RUN FAR FAR AWAY.".mysqli_connect_error());
  47. }
  48. /*---- Bio Update -----*/
  49. if($bio){
  50. $update_bio = "UPDATE users SET bio='$bio' WHERE email='$email'";
  51. if(mysqli_query($connection, $update_bio)){
  52. echo "Update successful.<br />";
  53. }else{
  54. echo "Something went wrong -- ". mysqli_error($connection);
  55. }
  56. }
  57. /*---- Locations Updates -----*/
  58. if($country){
  59. $update_country = "UPDATE users SET location_country='$country' WHERE email='$email'";
  60. if(mysqli_query($connection, $update_country)){
  61. echo "Update successful.<br />";
  62. }else{
  63. echo "Something went wrong -- ". mysqli_error($connection);
  64. }
  65. }
  66. if($state){
  67. $update_state = "UPDATE users SET location_state='$state' WHERE email='$email'";
  68. if(mysqli_query($connection, $update_state)){
  69. echo "Update successful.<br />";
  70. }else{
  71. echo "Something went wrong -- ". mysqli_error($connection);
  72. }
  73. }
  74. if($town){
  75. $update_town = "UPDATE users SET location_town='$town' WHERE email='$email'";
  76. if(mysqli_query($connection, $update_town)){
  77. echo "Update successful.<br />";
  78. }else{
  79. echo "Something went wrong -- ". mysqli_error($connection);
  80. }
  81. }
  82. /*---- Inserts Picture Update -----*/
  83. if($uploaded){
  84. $update_photo = "UPDATE users SET default_image='$new_file_name' WHERE email='$email'";
  85. if(mysqli_query($connection, $update_photo)){
  86. echo "Update Successful.";
  87. }else{
  88. echo "Something went wrong -- ". mysqli_error($connection);
  89. }
  90. }
  91. header("Location: edit-profile.php");
  92. mysqli_close($connection);
  93. ?>