带有移动应用程序的PHP Web服务

时间:2014-03-12 12:23:47

标签: php android cordova web service

我想创建一个移动应用程序,phonegap winch连接到外部oracle数据库。我首先需要创建一个Web服务,您可以看到我的代码并告诉我,如果我创建的是一个体贴的Web服务

的index.html

<html><head>
<script src="jquery.min.js"></script>
<script src="jsjsjs.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id='logindiv'>

        <label>Username:</label>
            <input name="username"  id="username" type="text">
        <label>Password:</label>
            <input name="password" id="password" type="password">
            <input value="Submit" name="submit" class="submit" type="submit" onclick='chk_ajax_login_with_php();'>
        <div id='status'></div>
</div>   
</body>
</html>

my jsjsjs.js

    <script>
function chk_ajax_login_with_php(){
  var username=document.getElementById("username").value;
  var password=document.getElementById("password").value;

    var params = "username="+username+"&password="+password;
           var url = "http://192.168.1.14/test_login/login.php";
                $.ajax({
                               type: 'POST',
                               url: url,
                               dataType: 'html',
                               data: params,
                               beforeSend: function() {
                                 document.getElementById("status").innerHTML= 'checking...'  ;
                                         },
                               complete: function() {

                               },
                               success: function(html) {


                                     document.getElementById("status").innerHTML= html;
                                     if(html=="success"){

                                       window.location = "http://192.168.1.14/test_login/test.php"

                                     }

                                }
                       });

}
</script>

的login.php

 <?php
session_start();
try {
$dbh = oci_connect('test_bd', '123456', 'localhost/XE');
} catch (PDOException $e)
{
    echo $e->getMessage();
}
if ($_POST['username'] != null and $_POST['username'] != "" and $_POST['password'] != null and $_POST['password'] != "")
{
$username = $_POST['username'];
$password = $_POST['password'];
$sth = oci_parse($dbh ,"SELECT * FROM utilisateur WHERE LOGIN='$username' and PASS='$password'");
oci_execute($sth);
if(oci_fetch($sth)){
       echo "Nice";
    }
    else { echo "nono";}



}     
?>    

0 个答案:

没有答案