You are not writing to the database, and the columns have numbers as names

1

This is a part of the code that is not writing to the database. Can you help me?

 case 'questao':

   include "conect.php";
   $bd ="questoes";             
   $banco = mysqli_select_db($conexao,$bd) or (mysqli_error());

   $categoria=$_POST["categoria"];
   $enunciado=$_POST["enunciado"];
   $a=$_POST["1"];
   $b=$_POST["2"];
   $c=$_POST["3"];
   $d=$_POST["4"];
   $e=$_POST["5"];
   $resposta=$_POST["resposta"];

   mysqli_query($conexao, "INSERT INTO perguntas(1,2,3,4,5,categoria,enunciado,resposta)VALUES '$a','$b','$c','$categoria','$d','$e','$enunciado','$resposta' )");
   echo "Questoes inseridas com sucesso";

   break;   
    
asked by anonymous 10.08.2016 / 01:11

1 answer

2

It is NOT advisable to use numbers as identifiers of tables or columns but it is possible to use them as long as names are escaped with backticks, this is also useful for special characters, accented characters and reserved words like DESC for example .

Example - sqfiddle

CREATE  TABLE '10' (
  'id' INT NOT NULL AUTO_INCREMENT ,
  '1' VARCHAR(45) NULL ,
  '2' VARCHAR(45) NULL ,
  PRIMARY KEY ('id') );

Correct insert:

insert into '10' ('1', '2') values ('a', 'b')

wrong insert:

insert into 10 (1, 2) values ('a', 'b')
    
10.08.2016 / 02:19