2011-08-10 29 views
0
<!-- this is my conexion.html --> 


<!DOCTYPE html> 
<html> 
<head> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js">  </script> 
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script> 

</head> 


<body> 


<!-- call ajax page --> 
<div data-role="page" id="callAjaxPage"> 
    <div data-role="header"> 
     <h1>Connexion</h1> 
     <a href="index.html" data-icon="home" data-iconpos="notext" class="ui-btn-right jqm-home">Home</a> 
    </div> 

    <div data-role="content"> 
     <div data-role="collapsible" data-collapsed="false"> 
       <h3>Sign in</h3> 
     <form id="callAjaxForm" method="post" action="conexion.php"> 
      <div data-role="fieldcontain"> 
       <label for="email">Email</label> 
       <input type="text" name="email" id="email" /> 

       <label for="password">Password</label> 
       <input type="password" name="password" id="password" /> 
       <h3 id="notification"></h3> 
       <button data-theme="b" id="submit" type="submit">Go</button> 
      </div> 
     </form> 

     </div> 
     <div data-role="collapsible" data-collapsed="true"> 
      <h3>Create an account </h3> 
     </div> 
    </div> 

    <div data-role="footer"> 
     <h1>Pied de page</h1> 
    </div> 
</div> 
</body> 
    </html> 

    <!--- this is my conexion.php --> 

    <?php 

include('config.php');// connexion to mysql 

$email = $_POST['email']; 
$password = $_POST['password']; 
$request=mysql_query("select * from utilisateur where nom='$email' and password='$password'"); 
$count=mysql_num_rows($request); 
if ($count==0){ 
    echo "User not found"; 
} 
else echo "Utilisateur founded"; 

?> 

回答

0

jQuery mobile將enhance forms with ajax by default(你不必手動爲它寫ajax)。

嘗試將表單的動作設置爲處理程序的php文件,並讓jQuery移動完成其餘部分。例如:

<form method="post" action="conexion.php"> 
    ... 
    <input type="submit" /> 
</form> 

讓我們知道你是怎麼去的!

編輯: 基於在評論中討論的,你還需要一些輸出添加到您的conexion.php文件。

我也建議在將其添加到SQL查詢之前轉義任何用戶輸入(爲了安全起見)。例如:

<?php 
    // conexion.php 

    include('config.php');// connexion to mysql 

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

    // Escape user input (unless magic quotes has done it already) 
    if (!get_magic_quotes_gpc()) { 
     $email = mysql_real_escape_string($email); 
     $password = mysql_real_escape_string($password); 
    } 

    $request=mysql_query(sprintf(
     "select * from utilisateur where nom='%s' and password='%s'", 
     $email, 
     $password 
    )); 
    $count = mysql_num_rows($request); 


?> 
<div data-role="page"> 
    <?php 
     if ($count==0){ 
      echo "<p>Username or password invalid.</p>"; 
     } else { 
      echo "<p>You're in! <a href=\"secure-home.php\">Continue to the app</a>.</p>"; 
     } 
    ?> 
</div> 
+0

所以我可以刪除它? $阿賈克斯({ 類型: 「POST」, 網址: 「conexion.php」, 緩存:假的, 數據:FORMDATA, 成功:的onSuccess, 錯誤:onerror的 }); –

+0

應該可以,是的。你不應該需要整個腳本塊。它怎麼樣? – irama

+0

當我這樣做,有一個錯誤「未定義」,因爲「conexion.php」沒有收到電子郵件和密碼值 –