繁体   English   中英

如何将phongap应用程序与Web服务器中的数据库连接

[英]How can I connect my phongap app with the database in the webserver

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

是的,您必须更改URL,或者如果两个文件都在同一文件夹中,则只需使用

<form action="insert.php" method="post">

它适用于本地服务器和实时服务器。

试试这个代码

<form action="insert.php" method="post">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM