我是使用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