Page 1 sur 1

Comment créer automatiquement une table MySQL depuis un formulaire

Posté : 09 oct. 2018, 22:08
par tjoce05
Bonjour,

Comment générer automatiquement une table mySQL depuis un form. Les colonnes sont dynamiques à l'aide de jQuery.

Code : Tout sélectionner

<form name="mySQL_table" id="mySQL_table"> <fieldset> <legend>Create MySQL table</legend> <div style="display:block; height:100px;"> <label>Nom de la table</label> <input type="text" name="name_table" id="name_table" value="" class="width300" required /> Ajouter <input type="number" name="numColumn" id="numColumn" value="1" class="width80" /> colonne(s) <button type="button" id="btn_addColumn">Exécuter</button> </div> <div style="display:block"> <table id="table_create" width="95%"> <tr> <th width="20%">Nom</th> <th width="20%">Type</th> <th width="10%">Taille/valeurs</th> <th width="10%">Defaut</th> <th width="10%">Interclassement</th> <th width="10%">Attributs</th> <th width="5%">Null</th> <th width="5%px">Index</th> <th width="5%">A_I</th> <th width="5%"></th> </tr> <tr> <td> <input type="text" name="name_column[]" class="name_column" value="" class="width400" required /> </td> <td> <select name="type[]" class="type width200"> <option value="INT">INT</option> <option value="TINYINT">TINYINT</option> <option value="VARCHAR">VARCHAR</option> <option value="CHAR">CHAR</option> <option value="TEXT">TEXT</option> <option value="DATE">DATE</option> <option value="DECIMAL">DECIMAL</option> <option value="FLOAT">FLOAT</option> </select> </td> <td> <input type="number" name="taille[]" value="" class="taille width80" required / > </td> <td> <select name="defaut[]" class="defaut width150"> <option value="Aucune">Aucune</option> </select> </td> <td> <select name="interclassement[]" class="interclassement width200"> <option value="utf8_general_ci">utf8_general_ci</option> </select> </td> <td> <select name="attributs[]" class="attributs width200"> <option value="BINARY">BINARY</option> <option value="UNSIGNED" selected>UNSIGNED</option> <option value="UNSIGNED_ZEROFIL">UNSIGNED ZEROFIL</option> <option value="CURRENT_TIMESTAMP">on update CURRENT_TIMESTAMP</option> </select> </td> <td> <input type="checkbox" name="null[]" class="null" value="NOT NULL" /> </td> <td> <select name="index[]" class="index width150"> <option value="0">...</option> <option value="PRIMARY KEY">PRIMAIRE</option> <option value="UNIQUE">UNIQUE</option> <option value="INDEX">INDEX</option> <option value="FULLTEXT">FULLTEXT</option> </select> </td> <td> <input type="checkbox" name="A_I[]" class="A_I" value="AUTO_INCREMENT" /> </td> <td></td> </tr> </table> </form>
and with php :

Code : Tout sélectionner

/*$sql = "CREATE TABLE IF NOT EXISTS ".$name_table." ( ID bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, "; foreach ...{ bigint(20) UNSIGNED NOT NULL,)... } PRIMARY KEY (ID) )"; if ($connect->query($sql) === TRUE) { printf("Table ".$name_table." successfully created.\n"); }else{ printf("Table ".$name_table." failed.\n");

Re: Comment créer automatiquement une table MySQL depuis un formulaire

Posté : 29 oct. 2018, 00:40
par Patriboom
T'es sûr que tu veux ça ?
Ce me semble « dangereux ». N'importe qui pourra créer une table dans ta BDD ? Étrange!
Demande à ton jQuery d'appeler un fichier PHP et faire faire le travail par PHP. Tu me sembles sur la piste de ce que tu veux faire.
Quelle est ta question précisément ?
Quels résultats obtiens-tu ?