gpt4 book ai didi

javascript - 使用 PHP/MYSQL 在 PhoneGap 中注册不起作用

转载 作者:行者123 更新时间:2023-11-29 11:36:31 24 4
gpt4 key购买 nike

我正在使用phonegap 并编写一个简单的注册页面,该页面使用PHP/MYSQL 方法进行插入。这是我的代码,但它不起作用!所有路径和代码似乎都是正确的,但它不起作用,让我发疯:(有什么问题吗?

HTML 和 JS:

<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JoinX</title>
<script type="text/javascript">
$(document).ready(function() {
$("#register").click(function() {
var username = $("#username").val();
var password = $("#password").val();
var email = $("#email").val();
var dataString = "username=" + username + "&password=" + password + "&email=" + email + "&insert=";
if ($.trim(username).length > 0 & $.trim(password).length > 0 & $.trim(email).length > 0) {
$.ajax({
type: "POST",
url: "http://127.0.0.1/phonegap/insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function() {
$("#register").val('Connecting...');
},
success: function(data) {
if (data == "ok") {
alert("inserted");
$("#register").val('submit');
} else if (data == "error") {
alert("error");
}
}
});
}
return false;
});
});
</script>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<link rel="icon" href="icon.png">
<link rel="stylesheet" href="themes/joinx.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>

<body>
<div data-role="page" data-theme="a" id="login">
<div data-role="header" data-position="inline">
<h1>Welcome</h1>
</div>
<div data-role="content" data-theme="a">
<p align="center">Don't Have An Account? <a href="#signup" class="ui-link">Register Now!</a>.</p>
<label for="slider1">Username :</label>
<input type="text" name="username2" id="username2" data-theme="Login" />
<label for="slider1">Password :</label>
<input type="password" name="Password2" id="Password2" data-theme="Login" />
<input type="submit" name="login" id="login" value="Login" data-theme="Login" />
</div>
</div>
<div data-role="page" data-theme="a" id="signup">
<div data-role="header" data-position="inline">
<h1>Register A New Account</h1>
</div>
<div data-role="content" data-theme="a">
<p align="center">Already Have An Account? <a href="#login" class="ui-link">Sign In Here!</a>.</p>
<label for="slider1">Username :</label>
<input type="text" name="username" id="username" data-theme="Login" />
<label for="slider1">Password :</label>
<input type="password" name="Password" id="Password" data-theme="Login" />
<label for="slider1">Email Address :</label>
<input type="email" name="email" id="email" data-theme="Login" />
<input type="submit" name="register" id="register" value="Sign Up" data-theme="Sign Up" />
</div>
</div>
</body>

</html>

PHP 页面:

<?php
$servername = "localhost";
$username2 = "root";
$password = "";
$dbname = "joinx";
// Create connection
$conn = new mysqli($servername, $username2, $password, $dbname);
$conn->set_charset("utf8");

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$q = mysql_query("INSERT INTO `user` (`Username`,`Password`,`Email`) VALUES ('$username','$password','$email')");
if ($q)
echo "ok";
else
echo "error";
}
?>

编辑:我说它不起作用。我的意思是它不会发生任何事情!就像 HTML 静态页面一样...

最佳答案

Cordova PhoneGap 是用于构建混合应用程序的客户端框架。如果我没记错的话,您希望在 PhoneGap 中运行服务器端语言。这个解决方案根本不可能。

关于javascript - 使用 PHP/MYSQL 在 PhoneGap 中注册不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com