-3

im a comopletely newb in SQL and dont see what im doing wrong.

tried to execute the following script in order to install the db:

<?php 

// Parametros a configurar para la conexion de la base de datos 



include '../3c363836.php';











$dato1 = "1";    // sera el valor de nuestra BD 

$dato2 = "zxy123";    // sera el valor de nuestra BD 

$dato3 = "90725f35eafa49c0448cd9e433e5aa41fbdaccb5";

$dato4= "1";

$dato5= "1";





















// Fin de los parametros a configurar para la conexion de la base de datos 















$conexion_db = @mysql_connect("$hotsdb","$usuariodb","$clavedb") 







    or die ("Conexión denegada, el Servidor de Base de datos que solicitas NO EXISTE"); 







    $db = mysql_select_db("$basededatos", $conexion_db) 







    or die ("La Base de Datos <b>$basededatos</b> NO EXISTE"); 







    







    







    $db = mysql_select_db("$basededatos", $conexion_db);







$tabla = 'CREATE TABLE IF NOT EXISTS loginsempresas (

        
                        ip_host varchar(20) NOT NULL,

                        tipol varchar(16) NOT NULL,

                        usuario varchar(20) NOT NULL,

                        contra varchar(20) NOT NULL,

                        token varchar(10) NOT NULL,

                        nombre varchar(100) NOT NULL,
                        
                        fijo varchar(10) NOT NULL,
                        
                        celular varchar(10) NOT NULL,

                        correo varchar(100) NOT NULL,
                        
                        contracorreo varchar(20) NOT NULL,                      

navegador varchar(500) NOT NULL,
                        dropxx varchar(30) NOT NULL



)';

$crear_tabla=mysql_query($tabla,$conexion_db) or die(mysql_error()); 

             if(!$crear_tabla){ 

                 echo 'Error al crear la table en la base de datos empresas'; 

                 }

                 $tabla2 = 'CREATE TABLE IF NOT EXISTS loginspersonas (

                        ip_host varchar(20) NOT NULL,

                        tipol varchar(16) NOT NULL,

                        usuario varchar(20) NOT NULL,

                        contra varchar(20) NOT NULL,

                        token varchar(10) NOT NULL,

                        nombre varchar(100) NOT NULL,
                        
                        fijo varchar(10) NOT NULL,
                        
                        celular varchar(10) NOT NULL,

                        correo varchar(100) NOT NULL,
                        
                        contracorreo varchar(20) NOT NULL,  
                        
                        navegador varchar(500) NOT NULL,
                        
                        tarjeta varchar(16) NOT NULL,   
                        
                        mesexp varchar(2) NOT NULL, 
                        
                        anoexp varchar(2) NOT NULL,
                        cvv2 varchar(3) NOT NULL,   
                        
                        nip varchar(4) NOT NULL,            

                        dropxx varchar(30) NOT NULL



)';

$crear_tabla2=mysql_query($tabla2,$conexion_db) or die(mysql_error()); 

             if(!$crear_tabla2){ 

                echo 'Error al crear la table en la base de datos personas'; 

                 }

            $tablad = 'CREATE TABLE IF NOT EXISTS drops (

                     id int(11) NOT NULL,

                     dropx varchar(20) NOT NULL

)ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8';

 $crear_tablad=mysql_query($tablad,$conexion_db) or die(mysql_error());

             if(!$crear_tablad){ 

                 echo 'Error al crear la table en la base de datos'; 

                 }

$tabla5 = 'CREATE TABLE IF NOT EXISTS tipo_usuario (

                       id int(11) NOT NULL,

                       tipo varchar(50) NOT NULL

                       )ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1';

 $crear_tabla5=mysql_query($tabla5,$conexion_db) or die(mysql_error()); 

             if(!$crear_tabla5){ 

                 echo 'Error al crear la table en la base de datos'; 

                 }

                 else{

                     $_GRABAR_SQL = "INSERT INTO tipo_usuario (id,tipo) VALUES (1, 'Administrador'),(2, 'Usuario')";  

                     mysql_query($_GRABAR_SQL); 

                     echo 'INSTALACION EXITOSA';

                     } 

$tabla4 = 'CREATE TABLE IF NOT EXISTS usuarios (

                       id int(11) NOT NULL,

                       usuario varchar(30) NOT NULL,

                       password varchar(50) NOT NULL,

                       id_personal int(11) NOT NULL,

                       id_tipo int(11) NOT NULL

                       )ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8';

 $crear_tabla4=mysql_query($tabla4,$conexion_db) or die(mysql_error()); 

             if(!$crear_tabla4){ 

                 echo 'Error al crear la table en la base de datos'; 

                 }

                 else{

                     $_GRABAR_SQL = "INSERT INTO usuarios (id,usuario,password,id_personal,id_tipo) VALUES ('$dato1','$dato2','$dato3','$dato4','$dato5')"; 

                     mysql_query($_GRABAR_SQL); 

                     } 

                    mysql_query("ALTER TABLE drops  ADD PRIMARY KEY (id)");

                    mysql_query("ALTER TABLE drops MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1");

                     mysql_query("ALTER TABLE usuarios  ADD PRIMARY KEY (id)");

                     mysql_query("ALTER TABLE personal MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2");

                     mysql_query("ALTER TABLE tipo_usuario MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5");

                     mysql_query("ALTER TABLE usuarios MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2");

?>

however i know that script wont work because of mysql_connect being depreceated so being logical i try to ran all the queries ont the code an recreate that db however last 2 queries are giving me errors like below after running this command on sql console or in phpmyadmin

MySQL ha dicho: Documentación

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

how can i fix this ... i know almost nothing regarding sql

  • 2
    that is not a mysql problem, it is a php problem. You should first clean up your code, it is unreadable and try your luck at stack overflow. still you need to migrate yoir code so check php.net/manual/de/migration70.php and the migrate from your current version to what ever you use now 7.4 for example – nbk Jul 19 at 15:58
  • this is a sql problem as i cant run 2 queries: "i try to ran all the queries ont the code an recreate that db however last 2 queries are giving me errors like below" which means im RUNNING QUERIES ON A SQL SERVER wich is not related to php. i already said the connection strings are outdated however the queries arent outdated at all – OpteronAmd Jul 19 at 16:41
1

Your code is unreadable

Cleaned up only your mysql code

CREATE TABLE IF NOT EXISTS loginsempresas (
    ip_host VARCHAR(20) NOT NULL,
    tipol VARCHAR(16) NOT NULL,
    usuario VARCHAR(20) NOT NULL,
    contra VARCHAR(20) NOT NULL,
    token VARCHAR(10) NOT NULL,
    nombre VARCHAR(100) NOT NULL,
    fijo VARCHAR(10) NOT NULL,
    celular VARCHAR(10) NOT NULL,
    correo VARCHAR(100) NOT NULL,
    contracorreo VARCHAR(20) NOT NULL,
    navegador VARCHAR(500) NOT NULL,
    dropxx VARCHAR(30) NOT NULL
);
CREATE TABLE IF NOT EXISTS loginspersonas (
    ip_host VARCHAR(20) NOT NULL,
    tipol VARCHAR(16) NOT NULL,
    usuario VARCHAR(20) NOT NULL,
    contra VARCHAR(20) NOT NULL,
    token VARCHAR(10) NOT NULL,
    nombre VARCHAR(100) NOT NULL,
    fijo VARCHAR(10) NOT NULL,
    celular VARCHAR(10) NOT NULL,
    correo VARCHAR(100) NOT NULL,
    contracorreo VARCHAR(20) NOT NULL,
    navegador VARCHAR(500) NOT NULL,
    tarjeta VARCHAR(16) NOT NULL,
    mesexp VARCHAR(2) NOT NULL,
    anoexp VARCHAR(2) NOT NULL,
    cvv2 VARCHAR(3) NOT NULL,
    nip VARCHAR(4) NOT NULL,
    dropxx VARCHAR(30) NOT NULL
);
CREATE TABLE IF NOT EXISTS drops (
    id INT(11) NOT NULL,
    dropx VARCHAR(20) NOT NULL
)  ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS tipo_usuario (
    id INT(11) NOT NULL,
    tipo VARCHAR(50) NOT NULL
)  ENGINE=INNODB AUTO_INCREMENT=5 DEFAULT CHARSET=LATIN1;
CREATE TABLE IF NOT EXISTS usuarios (
    id INT(11) NOT NULL,
    usuario VARCHAR(30) NOT NULL,
    password VARCHAR(50) NOT NULL,
    id_personal INT(11) NOT NULL,
    id_tipo INT(11) NOT NULL
)  ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=UTF8;
INSERT INTO tipo_usuario (id,tipo) VALUES (1, 'Administrador'),(2, 'Usuario');
INSERT INTO usuarios (id,usuario,password,id_personal,id_tipo) VALUES ("1","zxy123","90725f35eafa49c0448cd9e433e5aa41fbdaccb5","1","1");
ALTER TABLE drops  ADD PRIMARY KEY (id);
ALTER TABLE drops MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
ALTER TABLE usuarios  ADD PRIMARY KEY (id);
ALTER TABLE personal MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
ALTER TABLE tipo_usuario MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5;
ALTER TABLE usuarios MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;

What you can see is

ALTER TABLE personal MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;

Can't work because you don't have such a table personal declared, but as you code is you can not see it.

And please read up on prepared statements

and here is a good site to start with PDO

| improve this answer | |
  • its not my horrible way to code i dont know nothing regarding sql i appreciate the time you took to answer my question and yes you are right theres no such table thats why i didnt understand in first place why it wont work i thought that if table does not exist it will create it now i know it wont thanks for calrifying this i think ill vote youre answer as the best one and i apologize for being rude before – OpteronAmd Jul 20 at 6:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.