Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql列计数不为';插入数据时,第1行的值计数不匹配错误_Php_Mysql - Fatal编程技术网

Php Mysql列计数不为';插入数据时,第1行的值计数不匹配错误

Php Mysql列计数不为';插入数据时,第1行的值计数不匹配错误,php,mysql,Php,Mysql,我在尝试将数据保存到mysql时出现此错误,我在这里看不到任何错误 $cons_no = $_POST['cons_no']; $ship_name = $_POST['ship_name']; $ship_location = $_POST['ship_location']; $phone = $_POST['phone']; $s_add = $_POST['s_add']; $r_name = $_POST['r_name']; $r_phone = $_POST['r_phone'];

我在尝试将数据保存到mysql时出现此错误,我在这里看不到任何错误

$cons_no = $_POST['cons_no'];
$ship_name = $_POST['ship_name'];
$ship_location = $_POST['ship_location'];
$phone = $_POST['phone'];
$s_add = $_POST['s_add'];
$r_name = $_POST['r_name'];
$r_phone = $_POST['r_phone'];
$r_add = $_POST['r_add'];
$type = $_POST['type'];
$weight = $_POST['weight'];
$invoice_no = $_POST['invoice_no'];
$qty = $_POST['qty'];
$book_mode = $_POST['book_mode'];
$freight = $_POST['freight'];
$mode = $_POST['mode'];
$pick_date = $_POST['pick_date'];
$pick_time = $_POST['pick_time'];
$status = $_POST['status'];
$comments = $_POST['comments'];
$r_country = $_POST['r_country'];
代码中唯一没有的是自动递增的cid

$sql = "INSERT INTO tbl_courier (cons_no, ship_name, ship_location, phone, s_add, r_name, r_phone, r_add,  type, weight, invoice_no, qty, book_mode, freight, mode, pick_date, pick_time, status, comments, r_country)
        VALUES('$cons_no', '$ship_name', '$ship_location', '$phone', '$s_add', '$r_name', '$r_phone', '$r_add', '$type', '$weight', $invoice_no, '$qty', '$freight', '$mode', '$pick_date', '$pick_time', '$status', '$comments', '$r_country')";   

我不知道您构建的SQL字符串,但我可以假设您有空值。。为了避免这种情况,您可以在指定值之前添加额外的检查

$status = isset($_POST['status'])?$_POST['status']:0; // default 0 if don't exists
编辑:


我看到您的查询,答案是:值语句中缺少字段
book\u mode

book\u mode。。。。。