【问题标题】:How can I connect my phongap app with the database in the webserver如何将我的 phonegap 应用程序与 Web 服务器中的数据库连接起来
【发布时间】: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


【解决方案1】:

是的,您必须更改网址或 如果您的两个文件都在同一个文件夹中,那么只需使用

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

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

【讨论】:

    【解决方案2】:

    试试这个代码

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

    【讨论】:

      猜你喜欢
      • 2013-08-03
      • 1970-01-01
      • 2016-06-22
      • 2013-05-08
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      相关资源
      最近更新 更多