take variable data from input

Asked

Viewed 152 times

0

Speak People! I have a system that registers products and creates what I need in the data field, but in a crucial part, after I create the fields I need it generates input with these fields! the problem is:

When sending via post the input is as below

<input type="text" name="campo[]" class="campo_input" placeholder="<?php echo $campo; ?>" />

I need to send the value of this field and separate to insert in the comic, because it is in a while!!!

<?php
include "conecta.php";
   mysql_set_charset('utf8');

$lista =$_POST['lista'];

$sku = implode(",", array_map(function ($item) {
 return sprintf('"%s"', $item);
}, $_POST['campo']));


$sqli = mysql_query ("INSERT INTO $lista VALUES ('', '".$sku."')")  or die(mysql_error());

if($sqli){
    echo $sku;
}
else {
    echo 'deu erro';
}

?>

he takes it nice, but I can’t separate to include in the bank, he gives the answer

Column count doesn't match value count at row 1

precisely because it takes the answer and does not separate, plays everything in a single column

1 answer

1


Column Count doesn’t match value Count at Row 1

=

The column count does not correspond to the value count in row 1

Check if the number of colunas query corresponds to the number of values passed in the value

Everything will depend on the variable value $lista

The query also has error '".$sku."' the correct is simply $sku as solutions below

  1. Assuming that HTML is composed of 4 inputs as an example below

    <input type="text" name="campo[]" class.....

  2. Assuming that the variable $lista is composed with the table name followed by the names of the columns in parentheses

    $lista = "nomeTabela(nomeColuna,nomeColuna1,nomeColuna2,nomeColuna3,nomeColuna4)";
    
  3. Your query should be

    $sqli = mysql_query ("INSERT INTO $lista VALUES ('', $sku)")  or die(mysql_error());
    
  4. If the table name is not in the variable $lista

    $sqli = mysql_query ("INSERT INTO nomeTabela $lista VALUES ('', $sku)")  or die(mysql_error());
    
  5. If the first column is AUTO_INCREMENT

    $lista = "nomeTabela(nomeColuna1,nomeColuna2,nomeColuna3,nomeColuna4)";
    
    $sqli = mysql_query ("INSERT INTO $lista VALUES ($sku)")  or die(mysql_error());
    
  6. There is the possibility of passing only the table name through the variable

    $lista = "nomeTabela"; 
    
    $sqli = mysql_query ("INSERT INTO $lista VALUES ($sku)")  or die(mysql_error());
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.