0

I am trying to put this into the database. And i am getting an unexpected error, however, saying Column count doesn't match value count at row 1. What is wrong with the query?

<?php 
    if($_REQUEST['command']=='update'){
    $charge   = $_REQUEST['ocharge'];
    $fname    = $_REQUEST['ofname'];
    $lname    = $_REQUEST['olname'];
    $mobile   = $_REQUEST['omobile'];
    $add1     = $_REQUEST['oadd1'];
    $add2     = $_REQUEST['oadd2'];
    $postcode = $_REQUEST['opostcode'];
    $state    = $_REQUEST['ostate'];
    $country  = $_REQUEST['ocountry'];
    $weight   = $_REQUEST['oweight'];
    $credit   = $_REQUEST['ocredit'];
    $pin      = $_REQUEST['opin'];
    $city     = $_REQUEST['ocity'];

        $date=date('Y-m-d');
        $time=time('H:i:s');
        $result=mysql_query("insert into order values ('$date','$time','$charge','$fname','$lname','$mobile','$add1','$add2','$postcode','$state','$country','$weight','$credit','$pin','$city')");
        $orderid=mysql_insert_id();    

        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $price=get_price($pid);
            $result1=mysql_query("insert into order_detail values ('$orderid','$pid','$q','$price')");
            if($result1 === FALSE)
            {
                die("Query Failed!".mysql_error().$result1);
            }

        }
        die('Thank You! your order has been placed!');
    }
?>
4

1 回答 1

2

你做这样的事情:

INSERT INTO table_name
VALUES (value1, value2, value3,...)

这需要您了解所有列及其顺序。您需要全部使用它们。

但是,如果您知道可以省略哪些列,则可以使用此方法:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

在这里,您指定要添加的列。如果所有其余列都定义了默认值或接受 NULL,那么您会没事的。

于 2013-08-30T22:43:32.733 回答