Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 18

Discussione: Select tra più mysql

  1. #1
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357

    Select tra più mysql

    Salve volevo un aiuto XD
    ho creato un form con un select "option" con diverse categorie all'interno... Ora ho creato diversi tabelle nel mysql.. come faccio ad indirizzare quiei dati nella tabella che viene scelta nel l'input.. in poche parole uno sceglie la categoria e i dati vanno nella tabella corrispondente a quella categoria.. Spero di essere stato chiaro..
    grazie in anticipo

  2. #2
    La <SELECT... avrà un nome, diciamo name="pippo".
    ora la select del db sarà
    $sql="SELECT * FROM ". $pippo. " ecc.
    pierogemin
    -------------
    -InterNET
    +CaberNET

  3. #3
    ho dimenticato di dire che ovviamente i nomi delle varie option devono essere esattamente quelli delle tabelle mysql
    pierogemin
    -------------
    -InterNET
    +CaberNET

  4. #4
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    ok gfrazie mille

  5. #5
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    e se li devo inserire? io ho fdatto cosi:

    form:
    Codice PHP:
    <form action="wiev.php" method="post" width="160" >
    <
    table border="0" cellpadding="1" cellspacing="0" align="center" width="147" >
    <
    tr 
    <
    td width="90" valign="top"
    <
    input name="name"  type="text" size="15" maxlength="100" value="Nome sito"  onfocus=\"this.value=''\">
    </td></tr>
    <tr> 
    <td width="
    90" valign="top"> 
    <input name="
    url"  type="text" size="15" maxlength="80" value="http://"  onfocus="this.value=''">
    </td></tr>
    <
    tr>
      <
    td valign="top"><select name="cat"><option>scegli la categoria</option><option name="portali" >Portali</option><option name="other">Other</option></select></td>
    </
    tr>
    <
    tr>
    <
    td valign=\"top\"><input name="webmaster" type=\"text\" size=\"15\" maxlength=\"255\" value="webMaster"></td>
    </tr>
    <tr> <td>
    <input name=\"banner\" type=\"text\" size=\"15\" maxlength=\"300\" value="
    Url Banner">
    </td>
    </tr>
    <tr>
    <td height=\"26\"  valign=\"top\"> 
    <a href=\"#\" onClick=\"winpiccola('smiles.php','Smiles','width=210,height=210,scrollbars=1')\" target=\"_self\" title=\"Apri la finestra con cli smiles\"><img src=\"smiles/cinesino.gif\" border=\"0\" alt=\"Apri la finestra con cli smiles\"></a> - <a href=\"#\" onClick=\"winpiccola('test.php','Smiles','width=245,height=50,scrollbars=1')\" target=\"_self\" title=\"Formattazione Testo\"><span class=\"tag2\">BBcode</span></a> - <input type="
    submit" value="GO" >
    </td>
    </tr> 
    </table>
    </form> 
    insert:
    Codice PHP:
    <?php
     
    include "connect.php"
      {if (
    $name == "Nome sito") {
        echo 
    "<span class=\"copy\">Riempi il campo NICK.</span>
    "
    ;
        } 
        else
      {
      
    mysql_query("INSERT INTO $cat VALUES (NULL,'".$name."','".$url."','".$webmaster."','".$banner."')") or die (mysql_error());
      echo 
    "Sei stato inserito con successo!

    "
    ;
      } 
    ?>
    nel tabele create nel mysql sono other e portali e tutti è due hanno questi valori: id` INT(11) NOT NULL AUTO_INCREMENT,
    `name` CHAR(80) NOT NULL,
    `url` CHAR(100) NOT NULL,
    `webmaster` CHAR(50),
    `banner` CHAR(150)

    pero facendo cosi nn va.. HELP ME

  6. #6
    Forse dico una cazzata ma prova a sostituire la riga
    mysql_query("INSERT INTO $cat VALUES (NULL,'".$name."','".$url."','".$webmaster."',".$b anner."')") or die (mysql_error());
    con
    mysql_query("INSERT INTO". $cat. "VALUES (NULL,'$name','$url','$webmaster','$banner')") or die (mysql_error());
    pierogemin
    -------------
    -InterNET
    +CaberNET

  7. #7
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    uhm.. no mi da errore... uff

  8. #8
    Quale errore?
    Cmq controlla che $cat venga ricevuta.
    metti echo $cat; prima della query anzi mettila anche prima della if.
    Questa degli echo è la migliore tecnica di debug.
    Se ne ricevi il valore corretto significa che l'errore è nella if o nella query
    pierogemin
    -------------
    -InterNET
    +CaberNET

  9. #9
    Utente di HTML.it L'avatar di kakashi
    Registrato dal
    Feb 2005
    Messaggi
    357
    ecco l'errore: Parse error: parse error in D:\Inetpub\webs\amworldit\public\lega\wiev.php on line 21

  10. #10
    Bravo ! e qual'à la riga 21?
    pierogemin
    -------------
    -InterNET
    +CaberNET

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.