【发布时间】:2016-10-22 11:50:41
【问题描述】:
我不熟悉使用 phonegap 创建移动应用程序。所以我正在尝试创建一个小表单,当用户单击提交时,数据应该转到我在 ServersFree.com 中创建的在线服务器
所以我打算只将 php 文件放到文件管理器中,并在使用 build 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>
【问题讨论】:
-
action="insert.php" 。根据您的文件位置更改它,
no need localhost.....
标签: php android cordova server