如何将信息更新到数据库中?

时间:2015-02-25 08:57:02

标签: php database if-statement

我在更新数据库方面遇到了问题,

这是我的第一页,



<div class="col-md-4">
  <div class="createnewbox">
    <form name="Edit Admin Infomation" class="form-horizontal" method="post" action="adminUpdateProductDetail.php?cat=<?php echo $product['categoryid']; ?>&code=<?php echo $product['productname']; ?>">
      <h2>Edit Product Information</h2>
      <div class="form-group">
        <label class="col-sm-2 control-label">Name</label>
        <br/>
        <br/>
        <div class="col-md-11">
          <input type="text" class="form-control" value="<?php echo $product['productname']; ?>" name="productname">
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-2 control-label">Price</label>
        <br/>
        <br/>
        <div class="col-md-11">
          <input type="text" class="form-control" value="<?php echo $product['price']; ?>" name="price">
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-2 control-label">Dimension</label>
        <br/>
        <br/>
        <div class="col-md-11">
          <input type="text" class="form-control" value="<?php echo $product['dimension']; ?>" name="dimension">
        </div>
      </div>

      <div class="form-group">
        <label class="col-sm-2 control-label">Description</label>
        <br/>
        <br/>
        <div class="col-md-11">
          <textarea type="text" class="form-control" rows="8" name="productinfo">
            <?php echo $product[ 'productinfo']; ?>
          </textarea>
        </div>
      </div>

      <div class="form-group">
        <div class="col-md-11">
          <input type="submit" value="Update Information" class="btn btn-success">
          <script>
            function reset() {
              location.reload();
            }
          </script>
          <button class="btn btn-info" onclick="reset()">undo</button>
        </div>
      </div>
      <?php ?>
    </form>
  </div>
</div>
&#13;
&#13;
&#13;

这是我的adminUpdateProductDetail.php,

&#13;
&#13;
<?php
        include 'adminNavBar.php';
        require 'dbfunction.php';

        $con = getDbConnect();

        $price = $_POST['price'];
        $name = $_POST['productname'];
        $info = $_POST['productinfo'];
        $dimension = $_POST['dimension'];
        $cat= $_GET['cat'];
        $code= $_GET['code'];
        ?>
        <div class="space">
            <div class="container">
                <div class="row">
                    <?php
                    if (!mysqli_connect_errno($con)) { 
                        $sqlQueryStr = "UPDATE product SET price = '$price', productname = '$name', productinfo = '$info', dimension = '$dimension'  WHERE categoryid = '$cat' AND productname = '$code'";
                        if (mysqli_query($con, $sqlQueryStr)) { 
                             $recordid = mysqli_insert_id($con);
                            

                          

                            mysqli_query($con, $sqlQueryStr);
                        }
                        mysqli_close($con);
                        echo "$name Product details updated.";
                    } else {
                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
                    }
                    ?>
                </div>
            </div>
        </div>
&#13;
&#13;
&#13;

我没有收到任何错误消息,系统回应成功。但我的数据库没有更新。我不确定哪里出错了。

1 个答案:

答案 0 :(得分:0)

试试这个

            <?php
                if (!mysqli_connect_errno($con)) { 
                    $sqlQueryStr = "UPDATE product SET price = '$price', productname = '$name', productinfo = '$info', dimension = '$dimension'  WHERE categoryid = '$cat' AND productname = '$code'";
                    if (mysqli_query($con, $sqlQueryStr)) { 
                         $result = mysqli_query($con, $sqlQueryStr);
                         if($result === FALSE){
                             printf("Erreur : %s\n", mysqli_error($link));
                         }
                         $recordid = mysqli_insert_id($con);
                    }
                    mysqli_close($con);
                    echo "$name Product details updated.";
                } else {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
            ?>
            </div>

帮助您的文档:http://php.net/manual/en/mysqli.query.php#example-1766程序风格

始终在mysqli_insert_id更新请求之后

mysqli_query 连接没有错误,但可以与查询