简体   繁体   English

php插入代码中的列值匹配错误

[英]the column value match error in php insert code

addtomeal.php addtomeal.php

<?php
     $hostname="localhost";
     $username="root";
     $password="tiger";


     $dbhandle = \mysqli_connect($hostname, $username, $password) 
  or die("Unable to connect to MySQL");

$select= \mysqli_select_db($dbhandle,"sample")
     or mysqli_error($dbhandle);
 $itemId= \filter_input(\INPUT_GET,'itemId');

 $orderid= \filter_input(\INPUT_GET,'orderid');
 $subtitle= \filter_input(\INPUT_GET,'subtitle');
 $price= \filter_input(\INPUT_GET,'price');
 $quantity= \filter_input(\INPUT_POST,'quantity');
 $tnumber= \filter_input(\INPUT_GET,'tnumber');

 if(!empty(\filter_input(\INPUT_POST,'addtomeal')))
 {
  $sql="insert into addtomeal(orderid,itemId,subtitle,price,quantity,tnumber)values
 (NULL,'$orderid',$subtitle',$price','$quantity','$tnumber')";

/* @var $result type */
 $result= \mysqli_query($dbhandle,$sql) or die(\mysqli_error($dbhandle));
}       

echo "success";
mysqli_close($dbhandle);

items 项目

     <html>
     <head>
     <link rel="stylesheet" type="text/css" href="display.css" >
     <title>Login Page</title>
     <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"> 

      </head>
      <body>


    <form name="customer" id='c1' method="post" action="cartdb.php">
   <script src="samcheck.js"></script>
    <div id="top">
        <?php session_start(); ?>

        <div id="toplbl">Welcome <?php  echo $_SESSION["name"]?></div>
        <?php session_start(); ?>
      <div id="toplbl1">This is Table Number <?php  echo $_SESSION["tnumber"]?></div>
    </div>

   <div id="d3"><?php echo "$descript1" ; ?> </div>     
    <div id="s3"><?php echo "$subtitle1" ;?> </div>  
    <div id="r3"><?php { echo "$price1" ;} ?> </div> 
    <div id='t3'><?php echo "$title1"; ?> </div>
    <label id="q1">Quantity</label>
    <input type='text' id='q' name='q' value='1'>
    <input type="hidden" name="itemId" value="<?php $itemId1 ?>">
    <input type ='button' name='plus' value='+' id='p' onclick="increase()">
    <input type='button' name='minus' value='-' id='m' onclick="decrease()">
    <input type='button' name='cancel' value='Cancel' id='cancel' onclick="location.href='customersvsoup.php'">
    <input type='submit' name='addtomeal' value='Add to my Meal' id='addtomeal'>


    <?php if($itemId==='oepd1007'){
    echo "<img src='getdesserticecreamimage.php?itemId=oepd1007' alt='image'> ";}
     ?>

    </form>
    </body>
</html>

I'm getting the error as Column count doesn't match value count at row 1. I have displayed all the values using echo statement from items.php to addtomeal.php, here im getting only the quantity. 我收到错误,因为列计数与第1行的值计数不匹配。我已经使用echos语句显示了从items.php到addtomeal.php的所有值,此处仅获取数量。 I have specified those in items.html page. 我已经在items.html页面中指定了那些。

You have a starting quote missing for both of these variables $price' and $subtitle' 您缺少这两个变量$price'$subtitle'的起始报价

(NULL,'$orderid', $subtitle', $price','$quantity','$tnumber')
                 ^ // there  ^ // there

change it to: 更改为:

(NULL,'$orderid','$subtitle','$price','$quantity','$tnumber')

It looks like there are missing quotes in your query: 您的查询中似乎缺少引号:

$sql = "insert into addtomeal (orderid, itemId, subtitle, price, quantity, tnumber) values
(NULL, '$orderid', '$subtitle', '$price', '$quantity', '$tnumber')";

I do not know the types of your fields, I placed the quotes for all the fields, but if the types are numerical you do not need to use quotes. 我不知道您的字段的类型,我为所有字段都加上了引号,但是如果类型是数字,则不需要使用引号。

$sql = "INSERT INTO addtomeal (orderid, itemId, subtitle, price, quantity, tnumber) VALUES ('$orderid', '$itemid' ,'$subtitle', '$price', '$quantity', '$tnumber')"; $ sql =“将字符插入(序号,itemId,字幕,价格,数量,tnumber)VALUES('$ orderid','$ itemid','$ subtitle','$ price','$ quantity','$ tnumber ')”;

Don't enter NULL from query enter NULL from default value from your table structure at the time of creating a table i guess u are missing $itemid in the query, I have added that in above query and also removed NULL 不要在创建表时从查询中输入NULL从表结构的默认值中输入NULL我想你在查询中缺少$ itemid,我在上面的查询中添加了NULL并还删除了NULL

暂无
暂无

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

相关问题 SQL 插入值列表与列列表不匹配错误 - SQL Insert value list does not match column list error PHP代码,用于使用选择表格将复选框值插入到MySQL的特殊列中 - PHP code for insert checkbox value into spesific column on mysql with select form 错误:插入值列表与列列表不匹配:1136列计数与第1行的值计数不匹配 - Error: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 如果列为空,则PHP插入值 - PHP Insert value if column is null PDO错误:致命错误:插入值列表与列列表不匹配 - PDO error: Fatal error: Insert value list does not match column list Mysql 错误:列计数与第 1 行的值计数不匹配; 代码似乎与指南的建议相匹配, - Mysql error: Column count doesn't match value count at row 1; code appears to match suggestions of guides, 错误:INSERT INTO / VALUES(&#39;Array&#39;); 列数与第1行的值数不匹配 - Error: INSERT INTO / VALUES ('Array'); Column count doesn't match value count at row 1 MySql语句错误:SQLSTATE [21S01]:插入值列表与列列表不匹配:1136列计数与第1行的值计数不匹配 - MySql statement Error: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 插入值列表与列列表不匹配:1136 列计数与值计数不匹配 - Insert value list does not match column list: 1136 Column count doesn't match value count PHP数组值插入到mysqli列 - PHP arrays value insert to mysqli column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM