繁体   English   中英

SQL查询错误:列计数与第1行的值计数不匹配

[英]SQL Query Error: Column count doesn't match value count at row 1

尝试为我的价格数据创建插入字段时,我一直收到此错误。 在数据库上,它是浮点类型。 我不确定如何解决此问题,大多数在线答案都表明值和字段不匹配,但在我的代码中似乎并非如此。

insert.php:

  <?php
        $title="Insert a new item";
        $style="css/nav.css";
        $style2="css/form.css";
        include('includes/header.php');
        include('includes/nav.php');
        require_once('connect.php');
        $name = $_POST['Brand'];
        $description = $_POST['Description'];
        $price = $_POST['Price'];
        $caption = $_POST['caption'];
        $image = 'images/' . $_FILES["image"]["name"];
        $query="INSERT INTO product (Brand, Description, Price, Image, Name)
        VALUES('$name', '$description', '$price' '$image', '$caption')";
        if (mysqli_query($connection, $query)){
        echo "<p>New record added succesfully </p>";
        move_uploaded_file($_FILES["image"]["tmp_name"],
        "images/" . $_FILES["image"]["name"]); }
        else echo "SQL Query Error: " .mysqli_error($connection);
        mysqli_close($connection);
        ?>  

insert_form.php

<?php
$title="Insert a new item";
$style="css/nav.css";
$style2="css/form.css";
include('includes/header.php');
include('includes/nav.php');

?>      

    <form method="post" action="insert.php" enctype="multipart/form-data">
    <fieldset>
    <legend>Insert a New Record</legend>


    <div class="row">
        <label for="Brand" class="fixedwidth">Brand:</label>
        <input type="text" name="Brand" />
    </div>

    <div class="row">
        <label for="Description" class="textbox" >Description: </label>
        <textarea cols="50" rows="5" name="Description"></textarea>
    </div>

    <div class="row">
        <label for="Price" class="fixedwidth">Price:</label>
        <input type="text" name="Price" />
    </div>

    <div class="row">
        <label for="Image" class="fixedwidth">Image</label>
        <input type="file" name="image" />
    </div>

    <div class="row">
        <label for="Name" class="fixedwidth">Image Caption</label>
        <input type="text" name="caption" />
    </div>

    <div class="row">
        <input type="submit" name="submit" value="Add" />
        <input type="reset" value="Clear" />
    </div>
    </fieldset>                 
    </form>

<?php
        include('includes/footer.php');
?>  

您的查询有误,

'$price' '$image',

更改为

'$price', '$image',

祝好运!

   $query="INSERT INTO product (Brand,Description,Price,Image,Name)
    VALUES('$name','$description','$price','$image','$caption')";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM