2017-06-21 103 views
0

我想插入在phpMyAdmin 数据有两个表一个是方法add_item等是PREC 在方法add_item表它包含“ITEM_ID(小学重点),ITEM_NAME,item_shape” 和PREC表包含Prec_id作为Primary_key和ITEM_ID作为一个外键和其他 但是,当我想以PREC表将数据插入它的显示错误更新错误:列数并不在行匹配值计数1

Update-Error: INSERT INTO prec_item(item_id, precured_quantity, total_price, unit_price, retail_price, aapis_price, `precured_date`, `vendor_name`) VALUES (1, 12,12,12,12.12,'2017-06-21','q') Column count doesn't match value count at row 1 

请告诉我怎么解决这个问题我想知道如何在外键上添加数据

+0

。$ aapis_pri CE,而不是逗号这里$ market_price,$ aapis_pri CE – JYoThI

回答

0
INSERT INTO prec_item 
(item_id, precured_quantity, total_price, unit_price, retail_price, aapis_price, `precured_date`, `vendor_name`) 
VALUES (1, 12,12,12,12,12,'2017-06-21','q') 

试试上面的查询。

希望这将有助于

+0

我碰到的PHP表单数据是在那里工作很好? –

+0

是的,它工作正常。 –

+0

$ sql =“INSERT INTO prec_item(item_id,precured_quantity,total_price,unit_price,retail_price,aapis_price,'precured_date','vendor_name')VALUES($ item_name,$ quantity,$ actual_price,$ unit_price,$ market_price。$ aapis_price,' $ child_date”, '$ distributor_name')“;如果($ conn-> query($ sql)== TRUE){ header('Location:index.php?status = success'); } else { echo“更新错误:”。 $ sql。 “
”。 $ conn->的错误; } –

0

如果你读了错误的两倍意味着你会得到理解这个问题

Column count doesn't match value count at row 1

是什么意思,你列数不匹配你的价值计,

1st:你把值之间的点$market_price.$aapis_pri‌​ce而不是comma (,)这里$market_price,$aapis_pri‌​ce

第二:尝试用事先准备好的声明或PDO来避免SQL注入

+0

真的非常感谢我的水平是初学者,所以有时我不明白。 –

0

哥你应该试试这个代码,而不是你的代码希望它会帮助你。

require_once('dbconnect.php'); 
$insert = $db->query("INSERT INTO prec_item(item_id, precured_quantity, total_price, unit_price, retail_price, aapis_price, precured_date, vendor_name) VALUES('".$item_name."', '".$quantity."','".$actual_price."','".$unit_price."','".$market_price."','".$aapis_pri‌​ce."','".$child_date."','".$d‌​istributor_name."')"); 
mysqli_close($con); 

if ($conn->query($insert) == TRUE) 
{ 
header('Location: index.php?status=success'); 
} 
else 
{ 
    echo "Update-Error: " . $insert . "<br>" . $conn->error; 
    } 

dbconnect.php

<?php 
$dbHost = 'localhost'; 
$dbUsername = 'username'; 
$dbPassword = 'password'; 
$dbName = 'dbname'; 

//Connect with the database 
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); 

//Display error if failed to connect 
if ($db->connect_errno) { 
    printf("Connect failed: %s\n", $db->connect_error); 
    exit(); 
} 
?> 
你把值$ market_price点之间在
相关问题