Advertisement
Guest User

Untitled

a guest
May 4th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <?php
  2. session_start();
  3. #if(isset($_SESSION['User']))
  4. #{
  5. # header("Location: home.php");
  6. #}
  7. include_once 'dbconnect.php';
  8.  
  9. #if(isset($_POST['submit']))
  10. #
  11. $uname = $_POST['uname'];
  12. $email = $_POST['email'];
  13. $upass = $_POST['upass'];
  14.  
  15. $stmt = $dbh->prepare("SELECT COUNT(*) as `emailcount` FROM `User` WHERE email=:email");
  16. $stmt->execute(array("email" => $_POST['email']));
  17. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  18.  
  19. if ($row['emailcount'] > 0) {
  20. echo "<script>alert('Email $email already exists in our system. Please try another email')</script>";
  21. } else {
  22.  
  23.  
  24. $stmt = $dbh->prepare("INSERT INTO User(`uname`, `email`, `upass`) VALUES (:uname, :email, :upass)");
  25.  
  26. $stmt->execute(array("uname" => $_POST['uname'], "email" => $_POST['email'], "upass" => md5($_POST['upass'])));
  27. }
  28.  
  29. var_dump($uname); #these 3 var dumps display NULL when loading the page.
  30. var_dump($email);
  31. var_dump($upass);
  32.  
  33.  
  34.  
  35. ?>
  36.  
  37. <?php
  38. // Define a function for the PDO object
  39. function testdb_connect() {
  40. try {
  41. /*** mysql hostname ***/
  42. $hostname = 'localhost';
  43. /*** mysql username ***/
  44. $username = '-----';
  45. /*** mysql password ***/
  46. $password = '------';
  47.  
  48. $dbh = new PDO("mysql:host=$hostname;dbname=------", $username, $password);
  49. return $dbh;
  50. } catch(PDOException $e) {
  51. echo $e->getMessage();
  52. }
  53. }
  54.  
  55. $dbh = testdb_connect(); // call the function, create the connection
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement