Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $host = 'xxxx';
- $dbname = 'xxxx';
- $username = 'xxxx';
- $password = 'xxxx.';
- try {
- $conn = new PDO("mysql:host=$host; dbname=$dbname;", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- echo "$e->getMessage()";
- }
- session_start();
- include 'config.php';
- function getAddress(){
- $output = "";
- if (isset($_SESSION['userid'])){
- $userid = $_SESSION['userid'];
- try {
- $stmt = $conn->prepare('SELECT address FROM users WHERE id = :userid');
- $stmt->bindParam(':userid', $userid);
- $stmt->execute();
- $result = $stmt -> fetch();
- if(empty($result)){
- $output = "Your information cannot be retrieved";
- } else {
- $output = $result['address'];
- }
- } catch (PDOException $e) {
- $output = $e->getMessage();
- }
- $conn = null;
- } else {
- $output = "An error has occured, please try again";
- }
- return $output;
- }
- <?php
- session_start();
- include 'functions.php';
- ?>
- ...
- <p><?php echo getAddress();?></p>
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement