我正在尝试将客户的送货地址存储到我的mysql数据库中。正在执行代码,但未存储值。

该方法被调用,但在mysql数据库中该行未更新。

有人可以帮我吗?

<?php
    /* connecting to my database */
    $db = mysqli_connect('localhost', 'root', 'root', 'test');
    if (mysqli_connect_error()) {
        echo "Database connection failed with following errors" . mysqli_connect_error();
        die();
        /* Error handling */
    }
    /* Button pressed  */

    if ($_POST['buy']) {
        /* Post variable */
        $text = mysql_real_escape_string($_POST['adress']);
        /* Executing query */
        $query = mysqli_query($db, "INSERT INTO `test` `shipping` (`id`, `adress`, `product`) VALUES (NULL, 'hghghghghgh', '')");
    }
?>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2"> </div>
        // Product info //
        <form action="iphone.php" method="post">
            <div class="col-md-4">
                <div class="panel panel-default">
                    <div class="panel-heading">#6</div>
                    <div class="panel-body">
                        <img src="images/iphone.jpg" width="300px" height="250px" align="center">
                        <p>iPhone 6S </p>
                        <p class="price" name="price"> Total Price : 68,999/-</p>
                        <p><span  style="color:blue">Mode of payment</span> <span   style="color: green" > : Cash On Delivery </span></p>
                        <p class="price" name="price"> Shipping Adress </p>
                        <input type="textarea"  id="adress" name="adress" style="width:350px; height:200px"/>
                        <br /> <br />
                        <button type="submit" name="submit" value="buy" class="btn btn-primary btn-lg btn-block" class="btn btn-success" data-toggle="modal" data-target="#details-6">Buy now</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

最佳答案

更改需要完成。

1)变更

if ($_POST['buy']) {




if ($_POST['submit']) {


2)变更

$text = mysql_real_escape_string($_POST['adress']);




$text = mysqli_real_escape_string($db,$_POST['adress']);


3)变更

在这里,将点(。)放在testshipping之间。

$query = mysqli_query($db, "INSERT INTO `test` `shipping` (`id`, `adress`, `product`) VALUES (NULL, 'hghghghghgh', '')");




$query = mysqli_query($db, "INSERT INTO `test`.`shipping` (`id`, `adress`, `product`) VALUES (NULL, 'hghghghghgh', '')");


更新的代码

<?php

    $db = mysqli_connect('localhost', 'root', 'root', 'test');
    if (mysqli_connect_error()) {
        echo "Database connection failed with following errors" . mysqli_connect_error();
        die();
    }


    if ($_POST['submit']) {
        $text = mysqli_real_escape_string($db,$_POST['adress']);
        $query = mysqli_query($db, "INSERT INTO `test`.`shipping` (`id`, `adress`, `product`) VALUES ('', 'hghghghghgh', '')");
    }
?>

<div class="container-fluid">
<div class="row">
<div class="col-md-2"> </div>
    // Product info //
    <form action="iphone.php" method="post">
          <div class="col-md-4">
          <div class="panel panel-default">
          <div class="panel-heading">#6</div>
          <div class="panel-body">
              <img src="images/iphone.jpg" width="300px" height="250px" align="center">
              <p>iPhone 6S </p>
              <p class="price" name="price"> Total Price : 68,999/-</p>
              <p><span  style="color:blue">Mode of payment</span> <span   style="color: green" > : Cash On Delivery </span></p>
              <p class="price" name="price"> Shipping Adress </p>
              <input type="textarea"  id="adress" name="adress" style="width:350px; height:200px"/>
              <br /> <br />
              <button type="submit" name="submit" value="buy" class="btn btn-primary btn-lg btn-block" class="btn btn-success" data-toggle="modal" data-target="#details-6">Buy now</button>
          </div>
          </div>
          </div>
    </form>
</div>

09-05 20:14