【问题标题】:POST method in PHP is unable to post data to the database from mobile browsersPHP 中的 POST 方法无法从移动浏览器将数据发布到数据库
【发布时间】:2019-12-29 17:53:28
【问题描述】:

我正在处理一个用户注册表单,我将用户的用户名和密码存储在一个数据库表中。我的网页在桌面浏览器上运行良好。但是当我在 android 的 chrome 浏览器上尝试它时,它无法将任何数据发布到数据库中。它甚至没有显示我在 php.ini 中使用的回声。我是 php 新手。 我正在为我的网站使用 000webhost 的免费托管服务。

这是我的表单代码:

<form action="store.php" method="POST">
                <div class="form">
                    <div class="input_field">
                        <input type="text" name="rname" placeholder="Phone number, username, or email" class="input">
                    </div>
                    <div class="input_field">
                        <input type="password" name="renterPass" placeholder="Password" class="input">
                    </div>
                    <button type="submit" class="btn btn-primary btn-sm">
                    <div class="btn-primary btn-sm">
                            <a href="https://mailsenderdemo.000webhostapp.com/">Log In</a>
                    </div>
                </button>
                </div>
                <!--<input type="submit"-->
            </form>

而我使用的 PHP 代码是:

<?PHP
    header('Content-Type: text/plain');
    $name = $_POST['rname'];    
    $pass1 = $_POST['renterPass'];
    $servername = "localhost";
    $username = "xxxxxxx";
    $password = "xxxxxxx";
    $dbname = "xxxxxx";
    $con = mysqli_connect($servername,$username,$password,$dbname);
    if(!$con)
    {
        die("Error : ".mysqli_connect_error());
    }


    $sql = "INSERT INTO `new`(`name`, `password`) VALUES('$name','$pass1');";

    if(mysqli_query($con,$sql))
    {
        echo "Registration Done Successfully...";
    }
    else
    {
        echo "Something went Wrong...";
    }


    mysqli_close($con);
?>

【问题讨论】:

    标签: php http post bootstrap-4


    【解决方案1】:
    **Try This**        
        <form action="store.php" method="POST">
          <div class="form">
           <div class="input_field">
            <input type="text" name="rname" placeholder="Phone number, username, or email" class="input">
          </div>
           <div class="input_field">
              <input type="password" name="renterPass" placeholder="Password" class="input">
           </div>
           <button type="submit" name="submit" class="btn btn-primary btn-sm"></button>
           </div>
         </form>
        <?PHP
                $servername = "localhost";
                $username = "xxxxxxx";
                $password = "xxxxxxx";
                $dbname = "xxxxxx";
                $con = mysqli_connect($servername,$username,$password,$dbname);
                if(!$con)
                {
                    die("Error : ".mysqli_connect_error());
                }
                if(isset($_POST['submit'])){
                $name = $_POST['rname'];    
                $pass1 = $_POST['renterPass'];
    
    
                $sql = "INSERT INTO `new`(`name`, `password`) VALUES('$name','$pass1');";
    
                if(mysqli_query($con,$sql))
                {
                    echo "Registration Done Successfully...";
                }
                else
                {
                    echo "Something went Wrong...";
                }
            }
    
                mysqli_close($con);
            ?>
    

    【讨论】:

    • 其实我最近想通了。但是,无论如何,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 2017-02-07
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多