2017-08-29 834 views
0

嘗試爲我的價格數據創建插入字段時,我不斷收到此錯誤。在數據庫上它是一個浮點類型。我不知道如何解決這個問題,大多數在線答案表明值和字段不匹配,但在我的代碼中似乎不是這種情況。SQL查詢錯誤:列計數與第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'); 
?> 
+3

的可能的複製[PHP,MySQL錯誤:列計數不在行匹配值計數1](https://stackoverflow.com/questions/5931900/php-mysql-error-column-count-不匹配數值在第1行) – Danieboy

回答

1

您在您的查詢這裏有一個錯誤,

'$price' '$image', 

變化上面,

'$price', '$image', 

祝你好運!

+0

哈哈哇,非常感謝你討厭的小逗號! – jacob

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