【问题标题】:Trying to connect to a mysql database in phonegap尝试连接到phonegap中的mysql数据库
【发布时间】:2011-07-16 04:04:44
【问题描述】:

我正在尝试在 android 上创建一个让用户登录的应用程序,我正在使用 phonegap。 这是我的代码,但是当我运行它时出现错误

这是我的 index.html

<html>
<head>
<script type="text/javascript"  src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" >
function login() {
$(document).ready(function() {
var user = $("#user")[0].value;
var pass = $("#pass")[0].value;
$.ajax({
type:"GET",
url:"newlogin.php",
data: "user="+user+"&pass="+pass,
success: function(result){
if (result){
$("#message")[0].value = "Success "+result;
}
else {
$("#message")[0].value = "error";
}
}
});
});
}
</script>
<style type="text/css">
body{
margin:auto;
width:100%;
display: table;
background-color: #333;
}
form{
text-align: center;
height: 500px;
display: table-cell;
vertical-align: middle;
}
input{
font-size: 20px;
text-shadow: #ccc 2px 2px;
text-align: center;
}
input#message {
background-color: transparent;
border: 0;
color: white;
text-shadow: #5191C1 2px 2px;
}
</style>
</head>
<body>
    <form>
    <input type="text" size="25" id="user" onkeyup= "login()" />
    <br />
    <input type="text" size="25" id="pass" onkeyup= "login()"/>
    <br />
    <input type="text" size="25" id="message" value="hey" />
    </form>

</body>
</html>

这是它连接到的newlogin.php

<?php 
$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];

mysql_connect("localhost","root","sercet") or die(mysql_error());
mysql_select_db("book") or die(mysql_error());

$result = mysql_query("SELECT username,password,id FROM book_users WHERE username = '$user'");
while($row = mysql_fetch_array($result)) {
    if($pass == $row["password"]){
        echo $row["id"];
        } 
        else {
            echo "";
            }

    }

?>

希望你的代码能帮我找到解决这个问题的方法

我在显示消息的位置出现错误"Sucess + result" 我得到Sucess&lt;?php user =$_REQUEST('user').......

【问题讨论】:

  • 不好的问题。你得到什么错误?怎么会有人知道从哪里开始寻找?
  • 对不起,我尝试添加显示错误的图片,但堆栈溢出不允许我这样做,但我确实重写了我的问题。

标签: javascript android ajax jquery cordova


【解决方案1】:

我怀疑(因为您使用本地 url 来调用“您的服务器”并且您询问 phonegap 是否无法执行 php)您在手机上部署了一个带有 an 的 php 文件。 Phonegap 不能执行 php 你需要一个运行 php 的服务器。

【讨论】:

    【解决方案2】:

    更改您的代码:

    url:"http://域名/newlogin.php",

    例如:本地 (http://192.168.43.104/new/newlogin.php)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 2015-07-04
      • 1970-01-01
      • 2013-04-30
      • 2019-02-17
      相关资源
      最近更新 更多