I am trying to create an app on android which makes users login in and I am using phonegap. Here is my code but when i run it i get an error
here is my 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>
and here is the newlogin.php it connects to
<?php
$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];
mysql_connect("localhost","root","sercet") or die(mysql_error());
mysql_select_db("book") or die(mysql_er开发者_如何学Cror());
$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 "";
}
}
?>
I hope you code help me find the solution to this problem
I Get the error at where it shows the message where it reads "Sucess + result"
i get Sucess<?php user =$_REQUEST('user')
....... <- thats all i could see in the emulator
I am not sure if it might be that phonegap cannot execute php file
I am suspecting (because you use a local url for calling "your server" and you ask if phonegap can´t execute php) that you deployed a php file with your an to the phone. Phonegap can not execute php you need a server running php for that.
Change your code:
url:"http://domainname/newlogin.php",
eg: for local (http://192.168.43.104/new/newlogin.php)
精彩评论