Advertisement
Guest User

php

a guest
Feb 28th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. connect.php code:
  2. <?php
  3.  
  4.     $conn = mysqli_connect("localhost","root","1234","User");
  5.  
  6.     if($conn -> connect_error){
  7.         die("connection failed: ".$conn.connect_error);
  8.     }else{
  9.         echo "connection successful";
  10.     }
  11.  
  12.  
  13.  ?>
  14.  
  15. regist.php code:
  16.  
  17. <html>
  18. <head>
  19.     <title> Register  </title>
  20. </head>
  21. <body>
  22.  
  23.     <form action="doReg.php" method="post">
  24.    
  25.         Username: <input type="text" name="txtuser" placeholder="Username"><br>
  26.         Password: <input type="password" name="txtpass" placeholder="Password"><br>
  27.         <input type="submit" value="Register">
  28.    
  29.    
  30.     </form>
  31.         <p color: "red"><?php if(isset($_GET["err"])) echo $_GET["err"];  ?>
  32. </body>
  33.  
  34. </html>
  35.  
  36.  
  37.  
  38.  
  39.  
  40. doRegist.php code:
  41.  
  42.  
  43.  
  44. <?php
  45. include("connect.php");
  46.  
  47.     $user=$_POST["txtuser"];
  48.     $pass=$_POST["txtpass"];
  49.  
  50. if($user == ""){
  51.     header("Location: regist.php?err=Username tidak boleh kosong");
  52.  
  53. }else if($pass == ""){
  54.     header("Location: regist.php?err=Password tidak boleh kosong");
  55. }else{
  56.  
  57.     $query = "INSERT INTO MsMember (username,password) VALUES ('$user','$pass','user')";
  58.     mysqli_query($conn,$query);
  59.     header("Location: regist.php?err=Register Success!");
  60. }
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement