我是使用phonegap创建移动应用的新手。所以我试图创建一个小表单,当用户单击提交时,数据应该转到我在ServersFree.com中创建的在线服务器
所以我打算将php文件只放到文件管理器中,然后从html文件访问它,我将使用build phonegap创建apk文件后将其放入手机。这是正确的方法吗?
<?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>
答案 0 :(得分:0)
是的,您必须更改网址OR 如果您的两个文件都在同一文件夹中,那么只需使用
<form action="insert.php" method="post">
它适用于本地和实时服务器。
答案 1 :(得分:0)
试试这段代码
<form action="insert.php" method="post">