文本区域值未插入MYSQL数据库

时间:2016-05-04 08:55:05

标签: php html mysql css3

我正在尝试将客户的送货地址存储到我的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 个答案:

答案 0 :(得分:0)

需要进行更改。

1)更改

if ($_POST['buy']) {

if ($_POST['submit']) {

2)更改

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

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

3)更改

在这里,将点(。)放在test&amp;之间。 shipping

$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>