Advertisement
Guest User

connect

a guest
Apr 10th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.31 KB | None | 0 0
  1. <?php
  2.  
  3. //error_reporting(1);
  4. //ini_set('display_errors', 'ON');
  5. //$host = 'localhost';
  6. //$username = 'homestead';
  7. //$password = 'secret';
  8. //$database = 'library';
  9. //
  10. ////using mysqli drive
  11. ////$db = new mysqli($host, $username, $password, $database);
  12. //$dbConnection = $con = mysqli_connect($host,$username,$password,$database);
  13. ////var_dump($db->connect(localhost, precise64, root, library ));
  14. //var_dump($dbConnection,mysqli_connect_errno() );
  15. //
  16. ////would have given the parameter as the name of the database if only I'd created it
  17. ////if($db->connect(localhost, root, root, library )) {
  18. // // echo "success";
  19. //
  20. ////} else {
  21. // // echo $db->connect_error;
  22. //
  23. // //die("Wrong Credentials");
  24. //
  25. ////}
  26. //require_once "config.php";
  27. //
  28. //$firstname = $lastname = $email = $password = $confirm_password = "";
  29. //$firstname_err = $lastname_err = $email_err = $password_err = $confirm_password_err = "";
  30. //
  31. //if($_SERVER["REQUEST_METHOD"] == "POST"){
  32. // if(empty(trim($_POST["firstname"]))){
  33. // $firstname_err= "Please enter a firstname.";
  34. // } else{
  35. // // Prepare a select statement
  36. // $sql = "SELECT id FROM users WHERE firstname = ?";
  37. //
  38. // if($stmt = mysqli_prepare($conn, $sql)){
  39. // // Bind variables to the prepared statement as parameters
  40. // mysqli_stmt_bind_param($stmt, "s", $param_firstname);
  41. //
  42. // // Set parameters
  43. // $param_firstname = trim($_POST["firstname"]);
  44. //
  45. // // Attempt to execute the prepared statement
  46. // if(mysqli_stmt_execute($stmt)){
  47. // /* store result */
  48. // mysqli_stmt_store_result($stmt);
  49. //
  50. // // if(mysqli_stmt_num_rows($stmt) >= 1){
  51. // // $firstname_err = "This email is already taken.";
  52. // // } else{
  53. // // $email = trim($_POST["email"]);
  54. // // }
  55. // // }
  56. // else{
  57. // echo "Oops! Something went wrong. Please try again later.";
  58. // }
  59. // }
  60. // elseif($_SERVER["REQUEST_METHOD"] == "POST"){
  61. // if(empty(trim($_POST["lastname"]))){
  62. // $lastname_err= "Please enter a lastname.";
  63. // } else{
  64. // // Prepare a select statement
  65. // $sql = "SELECT id FROM users WHERE lastname = ?";
  66. //
  67. // if($stmt = mysqli_prepare($conn, $sql)){
  68. // // Bind variables to the prepared statement as parameters
  69. // mysqli_stmt_bind_param($stmt, "s", $param_lastname);
  70. //
  71. // // Set parameters
  72. // $param_lastname = trim($_POST["lastname"]);
  73. //
  74. // // Attempt to execute the prepared statement
  75. // if(mysqli_stmt_execute($stmt)){
  76. // /* store result */
  77. // mysqli_stmt_store_result($stmt);
  78. //
  79. // // if(mysqli_stmt_num_rows($stmt) >= 1){
  80. // // $firstname_err = "This email is already taken.";
  81. // // } else{
  82. // // $email = trim($_POST["email"]);
  83. // // }
  84. // // }
  85. // else{
  86. // echo "Oops! Something went wrong. Please try again later.";
  87. // }
  88. // }
  89. //
  90. // elseif(empty(trim($_POST["email"]))){
  91. // $email_err = "Please enter a email.";
  92. // } else{
  93. // // Prepare a select statement
  94. // $sql = "SELECT id FROM users WHERE email = ?";
  95. //
  96. // if($stmt = mysqli_prepare($conn, $sql)){
  97. // // Bind variables to the prepared statement as parameters
  98. // mysqli_stmt_bind_param($stmt, "s", $param_email);
  99. //
  100. // // Set parameters
  101. // $param_email = trim($_POST["email"]);
  102. //
  103. // // Attempt to execute the prepared statement
  104. // if(mysqli_stmt_execute($stmt)){
  105. // /* store result */
  106. // mysqli_stmt_store_result($stmt);
  107. //
  108. // if(mysqli_stmt_num_rows($stmt) >= 1){
  109. // $email_err = "This email is already taken.";
  110. // } else{
  111. // $email = trim($_POST["email"]);
  112. // }
  113. // } else{
  114. // echo "Oops! Something went wrong. Please try again later.";
  115. // }
  116. // }
  117. //
  118. // // Close statement
  119. // mysqli_stmt_close($stmt);
  120. // }
  121. //
  122. // // Validate password
  123. // if(empty(trim($_POST["password"]))){
  124. // $password_err = "Please enter a password.";
  125. // } elseif(strlen(trim($_POST["password"])) < 6){
  126. // $password_err = "Password must have atleast 6 characters.";
  127. // } else{
  128. // $password = trim($_POST["password"]);
  129. // }
  130. //
  131. // // Validate confirm password
  132. // if(empty(trim($_POST["confirm_password"]))){
  133. // $confirm_password_err = "Please confirm password.";
  134. // } else{
  135. // $confirm_password = trim($_POST["confirm_password"]);
  136. // if(empty($password_err) && ($password != $confirm_password)){
  137. // $confirm_password_err = "Password did not match.";
  138. // }
  139. // }
  140. //
  141. // // Check input errors before inserting in database
  142. // if(empty($firstname_err) && empty($lastname_err) && empty($email_err) && empty($password_err) && empty($confirm_password_err)){
  143. //
  144. // // Prepare an insert statement
  145. // $sql = "INSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?)";
  146. //
  147. // if($stmt = mysqli_prepare($conn, $sql)){
  148. // // Bind variables to the prepared statement as parameters
  149. // mysqli_stmt_bind_param($stmt, "ssss", $param_firstname, $param_lastname, $param_email, $param_password);
  150. //
  151. // // Set parameters
  152. // $param_firstname = $firstname;
  153. // $param_lastname = $lastname;
  154. // $param_email = $email;
  155. // $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
  156. //
  157. // // Attempt to execute the prepared statement
  158. // if(mysqli_stmt_execute($stmt)){
  159. // // Redirect to login page
  160. // header("location: login.php");
  161. // } else{
  162. // echo "Something went wrong. Please try again later.";
  163. // }
  164. // }
  165. //
  166. // // Close statement
  167. // mysqli_stmt_close($stmt);
  168. // }
  169. //
  170. // // Close connection
  171. // mysqli_close($conn);
  172. //}
  173. //?>
  174. <!---->
  175. <!--<!DOCTYPE html>-->
  176. <!--<html lang="en">-->
  177. <!--<head>-->
  178. <!-- <meta charset="UTF-8">-->
  179. <!-- <title>Sign Up</title>-->
  180. <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">-->
  181. <!--</head>-->
  182. <!--<body style="overflow: hidden;">-->
  183. <!--<div class="container text-center" style="width: 400px;background: #fcfcfc;margin: 70px auto;">-->
  184. <!-- <h2>Sign Up</h2>-->
  185. <!-- <p>Please fill this form to create an account.</p>-->
  186. <!-- <form action="register.php" method="post">-->
  187. <!-- <div class="form-group --><?php //echo (!empty($firstname_err)) ? 'has-error' : ''; ?><!--">-->
  188. <!-- <label>Firstname</label>-->
  189. <!-- <input type="text" name="firstname" class="form-control" value="--><?php //echo $firstname; ?><!--">-->
  190. <!-- <span class="help-block">--><?php //echo $firstname_err; ?><!--</span>-->
  191. <!-- </div>-->
  192. <!-- <div class="form-group --><?php //echo (!empty($lastname_err)) ? 'has-error' : ''; ?><!--">-->
  193. <!-- <label>Lastname</label>-->
  194. <!-- <input type="text" name="lastname" class="form-control" value="--><?php //echo $lastname; ?><!--">-->
  195. <!-- <span class="help-block">--><?php //echo $lastname_err; ?><!--</span>-->
  196. <!-- </div>-->
  197. <!-- <div class="form-group --><?php //echo (!empty($email_err)) ? 'has-error' : ''; ?><!--">-->
  198. <!-- <label>Email</label>-->
  199. <!-- <input type="text" name="email" class="form-control" value="--><?php //echo $email; ?><!--">-->
  200. <!-- <span class="help-block">--><?php //echo $email_err; ?><!--</span>-->
  201. <!-- </div>-->
  202. <!-- <div class="form-group --><?php //echo (!empty($password_err)) ? 'has-error' : ''; ?><!--">-->
  203. <!-- <label>Password</label>-->
  204. <!-- <input type="password" name="password" class="form-control" value="--><?php //echo $password; ?><!--">-->
  205. <!-- <span class="help-block">--><?php //echo $password_err; ?><!--</span>-->
  206. <!-- </div>-->
  207. <!-- <div class="form-group --><?php //echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?><!--">-->
  208. <!-- <label>Confirm Password</label>-->
  209. <!-- <input type="password" name="confirm_password" class="form-control" value="--><?php //echo $confirm_password; ?><!--">-->
  210. <!-- <span class="help-block">--><?php //echo $confirm_password_err; ?><!--</span>-->
  211. <!-- </div>-->
  212. <!-- <div
  213. input type="submit" class="btn btn-primary" value="Submit">-->
  214. <!-- <input type="reset" class="btn btn-default" value="Reset">-->
  215. <!-- </div>-->
  216. <!-- <p>Already have an account? <a href="login.php">Login here</a>.</p>-->
  217. <!-- </form>-->
  218. <!--</div>-->
  219. <!--</body>-->
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. <?php
  255. //connection
  256.  
  257. $con = mysqli_connect("", "homestead", "secret", "library");
  258.  
  259. // Check connection
  260. if (mysqli_connect_errno()) {
  261. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  262. }
  263. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement