Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- #if(isset($_SESSION['User']))
- #{
- # header("Location: home.php");
- #}
- include_once 'dbconnect.php';
- #if(isset($_POST['submit']))
- #
- $uname = $_POST['uname'];
- $email = $_POST['email'];
- $upass = $_POST['upass'];
- $stmt = $dbh->prepare("SELECT COUNT(*) as `emailcount` FROM `User` WHERE email=:email");
- $stmt->execute(array("email" => $_POST['email']));
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if ($row['emailcount'] > 0) {
- echo "<script>alert('Email $email already exists in our system. Please try another email')</script>";
- } else {
- $stmt = $dbh->prepare("INSERT INTO User(`uname`, `email`, `upass`) VALUES (:uname, :email, :upass)");
- $stmt->execute(array("uname" => $_POST['uname'], "email" => $_POST['email'], "upass" => md5($_POST['upass'])));
- }
- var_dump($uname); #these 3 var dumps display NULL when loading the page.
- var_dump($email);
- var_dump($upass);
- ?>
- <?php
- // Define a function for the PDO object
- function testdb_connect() {
- try {
- /*** mysql hostname ***/
- $hostname = 'localhost';
- /*** mysql username ***/
- $username = '-----';
- /*** mysql password ***/
- $password = '------';
- $dbh = new PDO("mysql:host=$hostname;dbname=------", $username, $password);
- return $dbh;
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- $dbh = testdb_connect(); // call the function, create the connection
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement