Hi 🙂
i have this problem
in this script, first i post the database name
then the tables list appears
so i input the table which data i want to show, but the scripts "forgets" the database i wanted to connect to (which i chose in the first place).
basically, first i choose a database with a post entry, then i choose the table with another post entry. it should show the data contained in that table.
but it doesen't. seems like this script makes the first input variable null (the one in which i entered the database name i wanted to connect to).
it's a frustrating problem, since i understood where is the problem, but i can't fix it.
anyone can help?
thanks
<HTML>
<HEAD>
<TITLE>Gestione Prodotti</TITLE>
</HEAD>
<BODY>
<H1>Gestione prodotti</H1>
<UL>
<?php
$host='localhost';
$user='admin';
$password='password';
$database='utenti';
$db=@mysql_connect($host, $user, $password)
OR DIE ("impossibile connettersi al server $host");
$nomedb=$_POST['categoriatext'];
$nometab=$_POST['gruppotext'];
$gruppi = "SHOW TABLES FROM $nomedb";
$result = mysql_query($gruppi);
IF (ISSET($_POST['categoriatext'])):
define (DBSCELTO, $_POST['categoriatext']);
mysql_select_db($_POST['categoriatext']);
?>
<LABEL>Gruppi disponibili: <SELECT name="gruppook" id="gruppook" size="10" />
<FORM action="<?php
$gruppi = "SHOW TABLES FROM $nomedb";
$elencogruppi = mysql_query($gruppi);
//$nomedbscelto=$nomedb;
WHILE ($rigagruppo = mysql_fetch_row($elencogruppi)) {
{
ECHO "{$rigagruppo[0]}\n";
}
?>" method="post">
<?php
ECHO "<option name='selezionegruppi' value='tabella'>$rigagruppo[0]</option> \n";
}
?>
</LABEL><BR /></FORM>
<FORM action="<?php ECHO $_SERVER['PHP_SELF']; ?>" method="post">
<LABEL>Gruppo da visualizzare:<INPUT type="text" name="gruppotext" /></LABEL><BR />
<INPUT type="submit" value="INVIA" />
</FORM>
</SELECT></LABEL> </FORM><BR />
<?php
ELSE:
?>
<LABEL>Categorie disponibili: <SELECT name="categoriaok" id="categoriaok" size="10" />
<FORM action="<?php ECHO $_SERVER['PHP_SELF']; ?>" method="post">
<?php
$listacategorie = mysql_list_dbs($db);
$i = 0;
$cnt = mysql_num_rows($listacategorie);
WHILE ($i < $cnt) {
$elencocategorie=mysql_db_name($listacategorie, $i);
$i++;
ECHO "<option name='selezione' value='database'>$elencocategorie</option> \n";
}
?>
</SELECT></LABEL> </FORM><BR />
<FORM action="<?php ECHO $_SERVER['PHP_SELF']; ?>" method="post">
<LABEL>Categoria da visualizzare:<INPUT type="text" name="categoriatext" /></LABEL><BR />
<INPUT type="submit" value="INVIA" />
</FORM>
<?php ENDIF;
IF (ISSET($_POST['gruppotext'])):
$nometab=$_POST['gruppotext'];
$elencoprodotti = mysql_query("SELECT * FROM $nometab");
while ($prodotto=@mysql_fetch_array($elencoprodotti))
{
echo '<p>' . $prodotto['id'] . ' ' . $prodotto['marca'] . ' ' . $prodotto['modello'] . ' ' . $prodotto['prodotto'] . ' ' . $prodotto['caratteristiche'] . ' ' . $prodotto['prezzo'] . '<p>';
}
ENDIF; ?>
</BODY>
</HTML>