423,674 Members | 1,946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,674 IT Pros & Developers. It's quick & easy.

php code executed but not displayed in XAMPP

P: 1
i am beginner in php .i created register page in html.php code to store data in my sql and redirect to login page.the code is executed and it is directed to login page but data is not stored in XAMPP.
my code is

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. // Check, if username session is NOT set then this page will jump to login page
  6. if (!isset($_SESSION['username'])) {header('Location: index.html');}
  7.  
  8. $host = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $database = "book";
  12. $dsn = "mysql:host=$host;dbname=$database";
  13. try {
  14. $conn = new PDO( $dsn, $username, $password );
  15. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16.  
  17. //$conn = null;
  18. }
  19. catch (PDOException $e) {
  20. $conn = null;
  21. exit("Connection failed: " . $e->getMessage());
  22. }
  23. ?>
  24. mysql_select_db('book');
  25.  
  26. $username = mysql_real_escape_string(filter_var(trim($_POST['username']), FILTER_SANITIZE_STRING));
  27. $password = mysql_real_escape_string(filter_var(trim($_POST['password']), FILTER_SANITIZE_STRING));
  28. $conpassword = mysql_real_escape_string(filter_var(trim($_POST['conpassword']), FILTER_SANITIZE_STRING));
  29. $email = mysql_real_escape_string(filter_var(trim($_POST['email']), FILTER_SANITIZE_STRING));
  30. $phone = mysql_real_escape_string(filter_var(trim($_POST['phone']), FILTER_SANITIZE_STRING));
  31.  
  32.  
  33.  
  34. $query = "INSERT INTO register (username,password,conpassword,email,phone) 
  35. VALUES('$username','$password','$conpassword','$email','$phone')"
  36. $result=mysql_query($query);
  37.  
  38. if($result)    
  39. {          
  40.  echo "<script type='text/javascript'>alert('You are details Successfully Registered. Please Note it your Voter ID.".$voter_id."!')</script>";
  41.  echo '<script type="text/javascript">
  42. window.location = "login.html";
  43. </script>';
  44. else
  45. {      
  46.  echo "<script type='text/javascript'>alert('Something Goes Wrong with server Please Try again!')</script>";
  47.  echo '<script type="text/javascript">
  48. window.location = "register.html";
  49. </script>';
  50. }
  51. ?>
Oct 6 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
PDO doesn’t work with mysql_* functions.
Oct 7 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.