Create mysql table by php

Asked

Viewed 34 times

-1

I’m trying to create a table in the database through php but I’m not getting it. By the way, even using mysqli_error no error is shown

if ($new_room != "" && $new_room != " ") {
            $consulta_sala = $mysqli->query("SELECT nome_sala FROM criadas WHERE nome_sala = '".$new_room."'");
            if(mysqli_num_rows($consulta_sala) >= 1){
                echo "Essa sala já exite !";
            }else{
                $insert_1 = $mysqli->query("INSERT INTO criadas (nome_sala) VALUES ('$new_room')");
                $insert_2 = $mysqli->query("CREATE TABLE '$new_room' (id int(255) NOT NULL, de varchar(255) NOT NULL, para varchar(255) NOT NULL,msg varchar(400) NOT NULL,hr varchar(20) NOT NULL)") or die(mysqli_error($insert_2));
            }

1 answer

-1


Not used by quotation marks (at least in Mysql) in table name. Remove the quotes that will work.

CREATE TABLE NOME_TABELA and not 'NOME_TABELA'

CREATE TABLE $new_room (id int(255) NOT NULL, de varchar(255) NOT NULL, para varchar(255) NOT NULL,msg varchar(400) NOT NULL,hr varchar(20) NOT NULL)
  • When I try to use auto_increment and primary_key, it does not create the table. Any solution ?

  • Probably your syntax is incorrect.

  • Try an alter table later.

Browser other questions tagged

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