Hi, i am a php and mysql total newbie. π
i have this problem: i want to create a new table into an existing database. i have no problems in creating the table in a fixed database, but i want to create it into an existing database which you choose from a dropdown box.
the box seems to work correctly but it doesn't π
i am missing something: how can i connect the highlighted item in the dropdown box to the query: mysql_select_db($nomecategoria,$db); so that the new group gets created inside the highlighted database?
(sorry for italian language variables, but $nomecategoria should be the database in which i go adding the new table.)
excuse me for my english, i hope you have understood my problem.. i have to do this script for a university exam :queasy:
many thanks in advance, here goes the code π
<html>
<head>
<title>Nuovo Gruppo</title>
</head>
<body>
<h1>Crea nuovo gruppo</h1>
<ul>
<?php
$host='localhost';
$user='admin';
$password='password';
$database='utenti';
$db=@mysql_connect($host, $user, $password)
or die ("impossibile connettersi al server $host");
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Categoria: <select name="categoriaok" id="categoriaok" size="1" />
<option selected name="categoriaok" id="categoriaok" value="">Scegli la categoria...</option>
<?php
$listacategorie = mysql_list_dbs($db);
$i = 0;
$cnt = mysql_num_rows($listacategorie);
$arraycategorie = array();
while ($i < $cnt) {
$elencocategorie=mysql_db_name($listacategorie, $i);
array_push($arraycategorie, "$elencocategorie");
print_r($arraycategorie);
$i++;
echo "<option name='selezione' value='categoriascelta'>$elencocategorie</option> \n";
} // size Γ¨ la dimensione della tendina, \n rende piΓΉ leggibile il codice html emesso dallo script
?>
</select></label> </form><br />
<?php
$nomecategoria=$_POST['categoriascelta'];
if (isset($_POST['nomegruppo'])):
//crea nuovo gruppo con il form
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Aggiungi un altro gruppo</a></p>
<?php
$nomegruppo=$_POST['nomegruppo'];
$campo1=$_POST['campo1'];
$campo2=$_POST['campo2'];
$campo3=$_POST['campo3'];
$campo4=$_POST['campo4'];
$campo5=$_POST['campo5'];
//crea tabella con almeno un campo
$creatabella="CREATE TABLE $nomegruppo(
$campo1 TEXT NOT NULL,
$campo2 TEXT,
$campo3 TEXT,
$campo4 TEXT,
$campo5 TEXT
)";
mysql_select_db($nomecategoria,$db);
mysql_query($creatabella,$db);
echo '<p>Aggiunto nuovo gruppo</p>';
else: //form per scegliere in quale categoria inserire il gruppo, come si
//chiama il gruppo e da che campi Γ¨ costituito ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Inserisci il nuovo gruppo:</p>
<label>Nome: <input type="text" name="nomegruppo" /></label><br />
<label>Campo1: <input type="text" name="campo1" /></label><br />
<label>Campo2: <input type="text" name="campo2" /></label><br />
<label>Campo3: <input type="text" name="campo3" /></label><br />
<label>Campo4: <input type="text" name="campo4" /></label><br />
<label>Campo5: <input type="text" name="campo5" /></label><br />
<input type="submit" value="INVIA" />
</form>
<?php endif; ?>
</body>
</html>