Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. $host = 'xxxx';
  2. $dbname = 'xxxx';
  3. $username = 'xxxx';
  4. $password = 'xxxx.';
  5.  
  6. try {
  7. $conn = new PDO("mysql:host=$host; dbname=$dbname;", $username, $password);
  8. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9. } catch (PDOException $e) {
  10. echo "$e->getMessage()";
  11. }
  12.  
  13. session_start();
  14. include 'config.php';
  15.  
  16. function getAddress(){
  17. $output = "";
  18. if (isset($_SESSION['userid'])){
  19. $userid = $_SESSION['userid'];
  20. try {
  21. $stmt = $conn->prepare('SELECT address FROM users WHERE id = :userid');
  22. $stmt->bindParam(':userid', $userid);
  23. $stmt->execute();
  24. $result = $stmt -> fetch();
  25. if(empty($result)){
  26. $output = "Your information cannot be retrieved";
  27. } else {
  28. $output = $result['address'];
  29. }
  30. } catch (PDOException $e) {
  31. $output = $e->getMessage();
  32. }
  33. $conn = null;
  34. } else {
  35. $output = "An error has occured, please try again";
  36. }
  37. return $output;
  38. }
  39.  
  40. <?php
  41. session_start();
  42. include 'functions.php';
  43. ?>
  44. ...
  45. <p><?php echo getAddress();?></p>
  46. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement