我是使用phonegap创建移动应用程序的新手。所以我试图创建一个小表单,当用户单击提交数据应该去我在ServersFree.com创建的在线服务器如何将我的phongap应用程序与网络服务器中的数据库连接起来
所以我打算把PHP文件只给文件管理器和从我将要使用构建phonegap创建apk文件后放到手机中的html文件访问它。这是做到这一点的正确方法吗?
<?php
$servername = "hin123.bugs3.com";
$username = "u137593186";
$password = "ulsdjj29822";
$dbname = "u137593186_user";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);}
$name = $_POST['Name'];
$age = $_POST['Age'];
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "INSERT INTO user (name, age, username, password)
VALUES ('$name', '$age','$username','$password')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
这是我的html文件
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/register.css" />
<title>Registration</title>
</head>
<body>
<form id='register' action='insert.php' method='POST'>
<fieldset >
<legend>Register</legend>
<form action="" method="post">
<label>Name :</label>
<br></br>
<input id="Name" name="Name" type="text">
<br></br>
<label>Age :</label>
<br></br>
<input id="Age" name="Age" type="text">
<br></br>
<label>UserName :</label>
<br></br>
<input id="username" name="username" placeholder="username" type="text">
<br></br>
<label>Password :</label>
<br></br>
<input id="password" name="password" placeholder="**********" type="password">
<br></br>
<input name="submit" type="submit" value="Submit">
<br></br>
<span><?php echo $error; ?></span>
</form>
</body>
</html>
行动= “insert.php”。根据你的文件位置改变它,'不需要localhost' ..... – Karthi