Prova cosi nn l'ho testato fammi sapere
codice:
<html>
<body>
<form name="form1" method="get" action="crea.php">
Inserisci il nome del Database: </p>
<input type="text" name="dbname">
Inserisci il nome della Tabella: </p>
<input type="text" name="dbtable">
<input type="hidden" name="lenght" value="<? echo $_GET['dbcampi'] ?>" >
<?php
for($i=0;$i<$_GET['dbcampi'];$i++){
echo'
Inserisci il nome del campo:';
echo"<input type=\"text\" name=\"campo$i\">";
echo"<SELECT NAME=\"tipo$i\">";
echo'<OPTION SELECTED value="VARCHAR(20)">varchar</OPTION>';
echo'<OPTION value="INT(10)">int</OPTION>';
echo'</SELECT>';
}
?>
<input type="submit" value="Invia">
</form>
</body>
</html>
<?
//Pagina crea.php
//inizializzo stringa
$stringaquery="";
//inizializzo array temp
$campi=array();
$tipo=array();
//controllo numerico
if(!is_numeric($_GET['lenght'])){
echo "Un campo che doveva essere un numero nn lo e'";
exit();
}
for ($k=0; $k<$_GET['lenght']; $k++){
$campi[$k]=addslashes(strip_tags($_REQUEST[campo.$k]));
$tipo[$k]=addslashes(strip_tags($_REQUEST[tipo.$k]));
if($k==$_GET['lenght']-1){
$stringaquery.= "$campi[$k] $tipo[$k] " ;
}else{
$stringaquery.=" $campi[$k] $tipo[$k] , ";
}
}
//per il debug
echo "$stringaquery";
$tabbody=addslashes(strip_tags($_REQUEST['db_table']));
mysql_query("CREATE TABLE `$tabbody` ($stringaquery)")or die("Errore".mysql_error());