#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Post ERRO: inserir compraColumn count doesn't match value count at row 1


    I NEED HELP !_!





    <?php
    session_start();
    require_once("conectar_mysql.php");
    require_once("conectar_postgres.php");
    include("conectar.php");

    $data = date('Y-m-d');
    $valorSubTotal=$_SESSION[T_TOTAL_GERAL];

    $id_usu=$_SESSION['USU_ID'];

    $compraEndereco = $_POST['endereco'];
    $compraNum= $_POST['numero'];
    $compraComp= $_POST['complemento'];
    $compraBairro= $_POST['bairro'];
    $compraCidade= $_POST['cidade'];
    $compraUF= $_POST['estado'];
    $compraCEP= $_POST['cep'];
    $consideracoes = $_POST['consideracoes'];

    //CAPTURA IP
    if ($_SERVER) {
    if($_SERVER["HTTP_X_FORWARDED_FOR"]){ $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; }
    elseif($_SERVER["HTTP_CLIENT_IP"]){ $ip = $_SERVER["HTTP_CLIENT_IP"]; }
    else{ $ip = $_SERVER["REMOTE_ADDR"]; }
    }else{
    if(getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR" );}
    elseif(getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); }
    else{ $ip = getenv( "REMOTE_ADDR" ); }
    }

    //GRAVAR PEDIDO
    $sqlP = "insert into compras values (
    '',
    '".$_SESSION['ID']."',
    '".$_SESSION['cod_post']."',
    '$compraEndereco',
    '$compraNum',
    '$compraComp',
    '$compraBairro',
    '$compraCidade',
    '$compraUF',
    '$compraCEP',
    '$pagamento',
    '$pagamentoTipo',
    '0',
    '".$_SESSION[T_TOTAL_GERAL]."',
    '2',
    '$consideracoes',
    '$data',
    '$ip',
    'Aguardando',
    ''
    );";

    //echo $sqlP; exit();

    $sqlP_res = mysql_query($sqlP) or die ('ERRO: inserir compra'.mysql_error());
    $id_compra=mysql_insert_id();
    $_SESSION[COMPRA_ID]=$id_compra;

    //GRAVAR ITENS DO PEDIDO
    $chave_cesta = @array_keys($_SESSION[cesta]);

    for($i=0; $i < sizeof($chave_cesta); $i++) {
    $indice = $chave_cesta[$i];

    $sqlI = "INSERT INTO compras_itens VALUES (
    '',
    '$id_compra',
    '".$_SESSION[cesta][$indice][ID]."',
    '".$_SESSION[cesta][$indice][NOME]."',
    '".$_SESSION[cesta][$indice][QTDE]."',
    '".$_SESSION[cesta][$indice][PRECO]."'
    )";
    $sqlI_res = mysql_query($sqlI) or die ('ERRO: inserir item no pedido.');
    }

    //FORMATA VALORES PARA TRANSAÇÃO
    $valorSubTotalf=number_format($valorSubTotal,2,".",",");
    $valorSubTotal=str_replace(".","",$valorSubTotalf);

    $valorTotalGeralFrete = $valorSubTotal;

    // PESQUISA DADOS DO CLIENTE
    $sqlCOMP = "SELECT * FROM cadastros WHERE cad_cpf = '".$_SESSION[CPF]."'";
    $resCOMP = mysql_query($sqlCOMP) or die ($sqlCOMP."<br><br>".mysql_error());
    $rowCOMP = mysql_fetch_array($resCOMP);

    $estadoE = $rowCOMP['cad_estadoE'];


    if(sizeof($_SESSION[cesta])>0){
    //PEGA A CHAVE
    $chave_cesta = @array_keys($_SESSION[cesta]);

    //EXIBE OS PRODUTOS DA CESTA
    for($i=0; $i<sizeof($chave_cesta); $i++) {
    $indice = $chave_cesta[$i];

    //$_SESSION['qtdprodutos'] = $i+1;

    $desc = $_SESSION[cesta][$indice][CODIGO];
    $valor = $_SESSION[cesta][$indice][PRECO];
    //$peso = $_SESSION[cesta][$indice][PESO];

    //TOTAL GERAL
    $subtotal2 = $_SESSION[cesta][$indice][QTDE] * $valor;
    //$pesosubtotal2+= $_SESSION[cesta][$indice][QTDE] * $peso;

    $_SESSION['TOTALGERAL2'] += $TotalGeral2 += $subtotal2;
    $_SESSION['PESOTOTAL2'] = $pesosubtotal2;

    }}

    //$valor = number_format($_SESSION[T_TOTAL_GERAL], 2, "," , ".");
    //echo $valor; exit();

    // ENVIA E-MAIL
    include('enviar_pedido_finalizado.php');

    unset($_SESSION[cesta]);
    unset($_SESSION['TOTALGERAL']);
    unset($_SESSION['PESOTOTAL']);
    session_unset();
    session_destroy();

    echo "<script type=\"text/javascript\"> alert('Pedido realizado com sucesso, em breve retornaremos o contato'); window.location.href='../index.php'; </script>";



    ?>
    Last edited by requinix; June 21st, 2013 at 01:42 PM.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    NEW USER GUIDE AND FAQ

    Let us know when you've edited your post to include what that guide suggests and to add &amp;#91;php] tags.

    Comments on this post

    • ptr2void agrees : ROFL at the title
    Last edited by requinix; June 21st, 2013 at 02:43 PM. Reason: blue. it's supposed to be blue
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    It is just as the error says! The number of values you're inserting here
    php Code:
    $sqlP = "insert into compras values (
    '',
    '".$_SESSION['ID']."',
    '".$_SESSION['cod_post']."',
    '$compraEndereco',
    '$compraNum',
    '$compraComp',
    '$compraBairro',
    '$compraCidade',
    '$compraUF',
    '$compraCEP',
    '$pagamento',
    '$pagamentoTipo',
    '0',
    '".$_SESSION[T_TOTAL_GERAL]."',
    '2',
    '$consideracoes',
    '$data',
    '$ip',
    'Aguardando',
    ''
    );";


    does not match the number of columns in your compras table. This is why you should generally use the form

    php Code:
    INSERT INTO table(`column1`,`column2`) VALUES (col1value, col2value);


    And enjoy your soon-to-be-hacked system thanks to your total disregard for SQL injection. Bobby Tables is waiting for folks like you.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Please read the new user guide.

    Your insert statement directly above that error message has the wrong number of arguments. Since you don't specify the columns nor did you supply us with the table definition that's all we can say.

    Count the fields in the query. Make sure they match the fields in the table (or just specify the fields within the query).
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo