2017-03-12 31 views
1
<button type='submit' action='#' class='btn btn-primary block full-width m-b' id='showsimple1'>Login</button> 

$name = $_POST['name']; 
$password = $_POST['password']; 


if(!($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `username` = ?s AND `password` = ?s", $name, sha1($password)))) 
    $(function() { 
    $('#showsimple1').click(function(){ 
     // Display a error toast, with a title 
     toastr.options = { 
      "closeButton": true, 
      "debug": false, 
      "progressBar": true, 
      "preventDuplicates": true, 
      "positionClass": "toast-top-right", 
      "onclick": null, 
      "showDuration": "400", 
      "hideDuration": "1000", 
      "timeOut": "7000", 
      "extendedTimeOut": "1000", 
      "showEasing": "swing", 
      "hideEasing": "linear", 
      "showMethod": "fadeIn", 
      "hideMethod": "fadeOut" 
     } 
     toastr.error('Username or password are wrong!') 
    });    

}) 

else { 
    if($_POST['r'] == 1){ 
     $path_info = parse_url($set->url); 
     setcookie("user", $name, time() + 3600 * 24 * 30, $path_info['path']); // set 
     setcookie("pass", sha1($password), time() + 3600 * 24 * 30, $path_info['path']); // set 
    } 
    $_SESSION['user'] = $usr->userid; 
    header("Location: $set->url/home.php"); 
    exit; 
} 

第一個代碼是我的提交按鈕添加在登錄敬酒時密碼或用戶名是錯誤的

我不能管理,使這項工作,我一直在試圖彈出敬酒密碼或用戶名輸入時是不正確的。我的代碼中總是存在解析錯誤。

+0

您不必包紮點擊監聽器裏你'toastr'剛刪除點擊監聽器 –

+0

我該如何具體做到這一點?對不起,我的速度很慢 –

+1

這裏有什麼混合的js和php? –

回答

0

寫javscript代碼中<script></script>標籤去

 <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css" rel="stylesheet"/> 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js"></script> 


     <form method="post" > 
     <input name="name" type="text"> 
     <input name="password" type="text"> 
     <button type='submit' action='#' class='btn btn-primary block full-width m-b' id='showsimple1'>Login</button> 
     </form> 


     <?php 

     if(!($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `username` = ?s AND `password` = ?s", $name, sha1($password)))) 
{ ?> 
      <script> 
       $(function() { 
        // Display a error toast, with a title 
        toastr.options = { 
         "closeButton": true, 
         "debug": false, 
         "progressBar": true, 
         "preventDuplicates": true, 
         "positionClass": "toast-top-right", 
         "onclick": null, 
         "showDuration": "400", 
         "hideDuration": "1000", 
         "timeOut": "7000", 
         "extendedTimeOut": "1000", 
         "showEasing": "swing", 
         "hideEasing": "linear", 
         "showMethod": "fadeIn", 
         "hideMethod": "fadeOut" 
        } 
        toastr.error('Username or password are wrong!') 
       });    
      </script> 
     <?php 
      }else { 
       if($_POST['r'] == 1){ 
        $path_info = parse_url($set->url); 
        setcookie("user", $name, time() + 3600 * 24 * 30, $path_info['path']); // set 
        setcookie("pass", sha1($password), time() + 3600 * 24 * 30, $path_info['path']); // set 
       } 
       $_SESSION['user'] = $usr->userid; 
       header("Location: $set->url/home.php"); 
       exit; 
      } ?> 
0

當你想顯示錯誤消息,當頁面提交,然後將其加載回,那麼你就不必把代碼顯示點擊收聽喜歡這裏面的代碼。這將是這樣

if(!($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `username` = ?s AND `password` = ?s", $name, sha1($password)))) 
     $(function() { 
      // Display a error toast, with a title 
      toastr.options = { 
       "closeButton": true, 
       "debug": false, 
       "progressBar": true, 
       "preventDuplicates": true, 
       "positionClass": "toast-top-right", 
       "onclick": null, 
       "showDuration": "400", 
       "hideDuration": "1000", 
       "timeOut": "7000", 
       "extendedTimeOut": "1000", 
       "showEasing": "swing", 
       "hideEasing": "linear", 
       "showMethod": "fadeIn", 
       "hideMethod": "fadeOut" 
      } 
      toastr.error('Username or password are wrong!') 
     });    

    else { 
     if($_POST['r'] == 1){ 
      $path_info = parse_url($set->url); 
      setcookie("user", $name, time() + 3600 * 24 * 30, $path_info['path']); // set 
      setcookie("pass", sha1($password), time() + 3600 * 24 * 30, $path_info['path']); // set 
     } 
     $_SESSION['user'] = $usr->userid; 
     header("Location: $set->url/home.php"); 
     exit; 
    } 

我只是指着你在哪裏錯了。 這不是用HTML,CSS和JS混合PHP的一個很好的做法。 你可以用MVC(模型 - 視圖 - 控制器)架構

+0

我看到謝謝你糾正我。有沒有一種方法可以在語句中連接toast函數而不用混合它們?我的意思是使其正確,而不僅僅是使其工作。 –

相關問題