2017-08-29 37 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- doesnt-match-value-count-at-row-1) – Danieboy

答えて

1

、上記に

'$price' '$image', 

変更、

'$price', '$image', 

幸運!

+0

haha​​ wow、非常に厄介な小さなカンマありがとう! – jacob

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