SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | - | require("config.php");
|
| 2 | + | if(isset($_GET['act']) ) |
| 3 | {
| |
| 4 | - | $username = $_POST['username']; |
| 4 | + | |
| 5 | - | $password = $_POST['pass']; |
| 5 | + | $act=$_GET['act']; |
| 6 | ||
| 7 | if($act=='check') | |
| 8 | - | $query = "SELECT * FROM admin WHERE username='$username' AND pass='$password'"; |
| 8 | + | {
|
| 9 | - | $result = mysql_query($query,$con) or die(mysqli_error()); |
| 9 | + | |
| 10 | - | $num_row = mysql_num_rows($result); |
| 10 | + | foreach($_POST as $n=>$v)$$n=$v; |
| 11 | - | $row=mysql_fetch_array($result); |
| 11 | + | require("config.php");
|
| 12 | - | if( $num_row >=1 ) {
|
| 12 | + | |
| 13 | - | |
| 13 | + | error_reporting(1); |
| 14 | // print_r($_POST); | |
| 15 | $username = $_POST['username']; | |
| 16 | - | |
| 16 | + | $password = $_POST['pass']; |
| 17 | - | |
| 17 | + | $type=0; |
| 18 | $a=array(); | |
| 19 | $sql=""; | |
| 20 | - | ?> |
| 20 | + | |
| 21 | $query = "SELECT * FROM admin WHERE username='$username' AND pass='$password'"; | |
| 22 | $result = mysql_query($query,$con);// or die(mysql_error()); | |
| 23 | $num_row = mysql_num_rows($result); | |
| 24 | if($num_row){
| |
| 25 | $type='admin'; | |
| 26 | $url="admin/index.php"; | |
| 27 | } | |
| 28 | $sql.="<br/>$query"; | |
| 29 | ||
| 30 | $query = "SELECT * FROM alumni WHERE username='$username' AND pass='$password'"; | |
| 31 | $result = mysql_query($query,$con);// or die(mysqli_error()); | |
| 32 | $num_row = mysql_num_rows($result); | |
| 33 | $sql.="<br/>$query"; | |
| 34 | if($num_row&&$type==0){
| |
| 35 | $type='alumni'; | |
| 36 | $url="alumni/index.php"; | |
| 37 | } | |
| 38 | ||
| 39 | //$row=mysql_fetch_array($result); | |
| 40 | ||
| 41 | if( $type) {
| |
| 42 | $_SESSION['user_name']=$username; | |
| 43 | $_SESSION['pass']=$password; | |
| 44 | $_SESSION['type']=$type; | |
| 45 | $a['stat']=1; | |
| 46 | $a['url']=$url; | |
| 47 | }else{
| |
| 48 | $a['stat']=0; | |
| 49 | $a['sql']=$sql; | |
| 50 | } | |
| 51 | ||
| 52 | $json=json_encode($a); | |
| 53 | ||
| 54 | die($json); | |
| 55 | ||
| 56 | } | |
| 57 | } | |
| 58 | //include "menu.php"; | |
| 59 | ?> | |
| 60 | <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
| 61 | <div id="isi_content"> | |
| 62 | <p> | |
| 63 | <h3>Form Login</h3> | |
| 64 | <div id="login"> | |
| 65 | <form action="proses_login2.php" method="post" id="myForm"> | |
| 66 | <table id="form_login"> | |
| 67 | <tr> | |
| 68 | <td>Username</td> | |
| 69 | <td><input type="text" name="username" /></td> | |
| 70 | </tr> | |
| 71 | <tr> | |
| 72 | <td>Password</td> | |
| 73 | <td><input type="password" name="pass"/></td> | |
| 74 | </tr> | |
| 75 | <tr> | |
| 76 | ||
| 77 | <td colspan="2" ><input name="Button" type="submit" class="Button" value="Masuak" | |
| 78 | onclick="checkLogin();return false" | |
| 79 | /> | |
| 80 | <a href="index.php?modul=daftar">Mendaftar</a></td> | |
| 81 | </tr> | |
| 82 | </table> | |
| 83 | </form> | |
| 84 | </div> | |
| 85 | </p> | |
| 86 | </div><!-- end isi Content --> | |
| 87 | <script> | |
| 88 | function checkLogin() | |
| 89 | {
| |
| 90 | var selectorform = 'form#myForm'; | |
| 91 | var datax = $(selectorform).serialize(); | |
| 92 | /* | |
| 93 | Ganti URL dengan alamat check login | |
| 94 | */ | |
| 95 | var request = $.ajax({
| |
| 96 | url: "?act=check", | |
| 97 | type: "POST", | |
| 98 | data: datax, | |
| 99 | dataType: "json" | |
| 100 | }); | |
| 101 | ||
| 102 | request.success(function(msg) {
| |
| 103 | console.log('data sudah terkirim');
| |
| 104 | if(msg.stat==0) | |
| 105 | {
| |
| 106 | alert('periksa kembali user anda');
| |
| 107 | $(".msg").append(msg.sql);
| |
| 108 | return false; | |
| 109 | }else{
| |
| 110 | alert('terima kasih atas loginnya');
| |
| 111 | window.location.href =msg.url; | |
| 112 | } | |
| 113 | ||
| 114 | }); | |
| 115 | } | |
| 116 | </script> | |
| 117 | <div class='msg'></div> | |
| 118 | <!--script yg di paling atas bs di pindah.. --> |