Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2.  
  3. function Email_gogo() {
  4.  
  5. if(!empty($_POST['email']))
  6. {
  7.  
  8. $mysql_hostname = '*****';
  9. $mysql_username = '*****';
  10. $mysql_password = '*****';
  11. $mysql_dbname = '*****';
  12.  
  13. try {
  14. $db= new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", `enter code here`$mysql_username, $mysql_password);
  15. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. } catch (PDOException $e) {
  17. exit( $e->getMessage() );
  18. }
  19. $query_email = "
  20. SELECT
  21. email
  22. from users
  23. where
  24. email = :email
  25. ";
  26.  
  27. $query_goes = array(
  28.  
  29. ':email' => $_POST['email']
  30.  
  31. );
  32.  
  33. Try{
  34. $stmt = $db->prepare($query_email);
  35. $stmt ->execute($query_goes);
  36. while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  37.  
  38. }
  39. }
  40. catch(PDOException $ex){
  41. echo 'ERROR: '. $ex->getMessage();
  42. }
  43. if($stmt->rowCount() > 0){
  44.  
  45. echo("That Email is already in use...");
  46. }
  47.  
  48.  
  49. }
  50.  
  51. }
  52.  
  53. ?>
  54.  
  55. <?php
  56.  
  57.  
  58. require("common.php");
  59. require_once("gogo.php");
  60.  
  61. if(empty($_SESSION['user']))
  62. {
  63.  
  64. header("Location: ../hound/login.php");
  65.  
  66.  
  67. die("Redirecting to ../hound/login.php");
  68. }
  69.  
  70. if(!empty($_POST))
  71. {
  72.  
  73. if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
  74. {
  75.  
  76. die("Please enter a valid email address...");
  77. }
  78.  
  79. }
  80. Email_gogo();
  81.  
  82. $array_value = array(
  83. ':email' => $_POST['email'],
  84. ':first_name' => $_POST['first_name'],
  85. ':last_name' => $_POST['last_name'],
  86. ':id' => $_POST['id']
  87. );
  88.  
  89.  
  90.  
  91. $query = "UPDATE users
  92. SET
  93. email = :email,
  94. first_name = :first_name,
  95. last_name = :last_name
  96.  
  97. WHERE
  98. id = :id
  99. ";
  100.  
  101.  
  102. try
  103. {
  104.  
  105. $stmt = $db->prepare($query);
  106. $result = $stmt->execute($array_value);
  107. }
  108. catch(PDOException $ex)
  109. {
  110.  
  111. die("Ouch, failed to run query: " . $ex->getMessage());
  112. }
  113.  
  114.  
  115.  
  116. header("Location: users.php");
  117.  
  118.  
  119. die("Redirecting to users.php");
  120.  
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement