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

Discussione: problema con form

  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2004
    Messaggi
    11

    problema con form

    salve, avrei un problema con il post di un form.

    il listato è questo :

    il form mi richiama la pagina passandogli il parametro menu
    ma lo script non passa oltre.

    if($page == "") {

    .......
    <form name="form1" method="post" action="?page=menu">
    .......
    }

    elseif($page == "menu")
    {
    }


    suggerimenti?

  2. #2
    if($_POST['page'] == "").....
    PHP LEARN - Guide, tutorial e articoli sempre aggiornati
    NUOVO: standardLib; il potente framework PHP é ora disponibile
    *******************************************
    Scarica oggi la tua copia di MtxEventManager

  3. #3
    Sperando di aver ben inteso il tuo problema

    Codice PHP:
    if($page == "") {    .......  <form name="form1" method="post" action="<?php echo $SERVER["PHP_SELF"]; ?>?page=menu">  .......  }    elseif($page == "menu")  {  }

  4. #4
    Riporta tutto il codice così si capisce meglio
    1. La variabile $page da dove arriva?
    2. Se usi post non puoi passare parametri, quello è il metodo get
    3. Per menu usa un campo hidden:
    <input type="hidden" name="page" value="menu">
    Coltiva Linux, Windows si pianta da solo!

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2004
    Messaggi
    11

    ecco il listato....

    Codice PHP:
    <?
    if(!isset($_GET['page'])) 
    {
      if(
    $_GET['page'] == "")
     {
    ?>
    <form name="form1" method="post" action="?page=menu">
    <table width="100%" border="0" cellspacing="3" cellpadding="0">
    <tr>
    <th width="34%" class="testo" scope="row"><div align="right">username</div></th>
    <td width="50%"><input name="username" type="text" class="poster"></td>
    </tr>
    <tr>
    <th class="testo" scope="row"><div align="right">password</div></th>
    <td><input name="password" type="password" class="poster"></td>
    </tr>
    <tr>
    <th colspan="2" class="testo" scope="row"><input name="Submit" type="submit" class="poster" value="Invia">
    {
    Codice PHP:
    <? include("../config.php"); ?>
    </th>
    </tr>
    </table>
    </form>
    Codice PHP:
    <? 
    }
    elseif(
    $_GET['page'] == "menu")...............

    Non funzia ancora

  6. #6
    Il form non è corretto devi usare:
    <form name="form1" method="post" action="<?php echo $SERVER["PHP_SELF"]; ?>">
    <input type="hidden" name="page" value="menu">
    <table width="100%" border="0" cellspacing="3" cellpadding="0">
    <tr>
    <th width="34%" class="testo" scope="row"><div align="right">username</div></th>
    <td width="50%"><input name="username" type="text" class="poster"></td>
    </tr>
    <tr>
    <th class="testo" scope="row"><div align="right">password</div></th>
    <td><input name="password" type="password" class="poster"></td>
    </tr>
    <tr>
    <th colspan="2" class="testo" scope="row"><input name="Submit" type="submit" class="poster" value="Invia">
    <?php include("../config.php"); ?>
    </th>
    </tr>
    </table>
    </form>
    Così "dovrebbe" funzionare, anche se mi sembra che ci sia un po' di confusione con le parentesi degli if così quelli è meglio se li metti tu dove devi.
    Un consiglio: non usare <? perchè è deprecato, usa solo il tag completo <?php
    Coltiva Linux, Windows si pianta da solo!

  7. #7
    Utente di HTML.it
    Registrato dal
    Sep 2004
    Messaggi
    11
    Le stò provando tutte ma non mi funzia .

    Non mi entra dentro l'elseif $_GET['page'] == "menu".
    mi torna sempre alla pagina di login.


    <?php
    if(!isset($_POST)) $_POST=$HTTP_POST_VARS;
    if(!isset($_GET)) $_GET=$HTTP_GET_VARS;
    if(!isset($_SERVER)) $_SERVER=$HTTP_SERVER_VARS;
    include("../config.php");
    ?>
    <link href="../nius_chimeralabs.css" rel="stylesheet" type="text/css">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th class="titolone" scope="row"><span class="Stile1">nius<span class="Stile2">ro </span></span></th>
    </tr>
    </table>


    <?php
    if(!isset($_GET['page']))
    {
    if($_GET['page'] == "")
    {
    ?>
    <form name="form1" method="post" action="<?php echo $SERVER["PHP_SELF"]; ?>">
    <input type="hidden" name="page" value="menu">
    <table width="100%" border="0" cellspacing="3" cellpadding="0">
    <tr>
    <th width="34%" class="testo" scope="row"><div align="right">username</div></th>
    <td width="50%"><input name="username" type="text" class="poster"></td>
    </tr>
    <tr>
    <th class="testo" scope="row"><div align="right">password</div></th>
    <td><input name="password" type="password" class="poster"></td>
    </tr>
    <tr>
    <th colspan="2" class="testo" scope="row"><input name="Submit" type="submit" class="poster" value="Invia">
    </th>
    </tr>
    </table>
    </form>
    <?php
    }
    elseif($_GET['page'] == "menu")

    {
    unset($_GET['page']);
    define("CONNESSIONE",true);
    define("ADMINISTRATION", true);
    define("USER_READ", true);
    include("../config.php");
    $row = mysql_num_rows($iea);
    if($row)
    ....................

  8. #8
    Questo non ha senso, $HTTP_POST_VARS , $HTTP_GET_VARS ecc.. sono depecati e in $_POST e $_GET ci sono già i valori del form.
    Codice PHP:
    <?php
    if(!isset($_POST)) $_POST=$HTTP_POST_VARS;
    if(!isset(
    $_GET)) $_GET=$HTTP_GET_VARS;
    if(!isset(
    $_SERVER)) $_SERVER=$HTTP_SERVER_VARS;
    include(
    "../config.php");
    ?>
    Ma se non è settato $_GET['page'] come fai a fare $_GET['page'] == "".
    Codice PHP:
    if(!isset($_GET['page'])) 
    {
      if(
    $_GET['page'] == "")
     {
    ?> 
    Sei sicuro di aver messo tutte le parentesi graffe al posto giusto pechè dal codice che hai riportato ne mancano diverse.
    Codice PHP:
    }
    elseif(
    $_GET['page'] == "menu")

        {
            unset(
    $_GET['page']);
            
    define("CONNESSIONE",true);
            
    define("ADMINISTRATION"true);
            
    define("USER_READ"true);
            include(
    "../config.php");
            
    $row mysql_num_rows($iea);
            if(
    $row)
                    .....................
    // } chiusa elseif
    // } chiusa di if(!isset($_GET['page'])) 
    Cerca di usare i tag php quando inserisci codice nel forum così si capisce meglio.
    Coltiva Linux, Windows si pianta da solo!

  9. #9
    Utente di HTML.it
    Registrato dal
    Sep 2004
    Messaggi
    11
    Grazie per la pazienza innanzitutto

    allora, ho cercato di mettere a posto tutto come suggerito, con risultato :

    Codice PHP:
    <?php
    //////////////// /Admin/index.php
    /////////// Nius Pro. 
    include("../config.php");
    ?>
    <link href="../nius_chimeralabs.css" rel="stylesheet" type="text/css">
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th class="titolone" scope="row"><span class="Stile1">nius<span class="Stile2">:pro </span></span></th>
      </tr>
    </table>


    <?php
      
    if($_GET['page'] == "")
     {
    ?>
    <form name="form1" method="post" action="<?php echo $SERVER["PHP_SELF"]; ?>">
        <input type="hidden" name="page" value="menu">
      <table width="100%"  border="0" cellspacing="3" cellpadding="0">
        <tr>
          <th width="34%" class="testo" scope="row"><div align="right">username</div></th>
          <td width="50%"><input name="username" type="text" class="poster"></td>
        </tr>
        <tr>
          <th class="testo" scope="row"><div align="right">password</div></th>
          <td><input name="password" type="password" class="poster"></td>
        </tr>
        <tr>
          <th colspan="2" class="testo" scope="row"><input name="Submit" type="submit" class="poster" value="Invia">
          </th>
        </tr>
      </table>
    </form>
    <?php
    }
    elseif(
    $_GET['page'] == "menu")

        {
            unset(
    $_GET['page']);
            
    define("CONNESSIONE",true);
            
    define("ADMINISTRATION"true);
            
    define("USER_READ"true);
            include(
    "../config.php");
            
    $row mysql_num_rows($iea);
            if(
    $row)
            {
                
    $risultato mysql_fetch_array($iea);
                
    ?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                <th colspan="2" class="poster" scope="row">Benvenuto: <?php echo $risultato["username"]; ?></th>
                  </tr>
                  <tr class="testo"><?php $username $risultato["username"]; $password $risultato["password"]; ?>
                <th scope="row">[url="?page=newsadd&username=<?php echo $username?>&password=<?php echo $password?>"]Aggiungi una news[/url]</th>
                   <th scope="row">[url="?page=newsedit&username=<?php echo $username?>&password=<?php echo $password?>"]Modifica Una News[/url]</th>
                </tr>
                  <tr class="testo">
                <th scope="row">[url="?page=newsedit&username=<?php echo $username?>&password=<?php echo $password?>"]Elimina una news[/url]</th>
                <th scope="row">-</th>
                  </tr>
                <?php 
                
    if($risultato["livello"] == "0"
                { 
                    
    ?>
                    <tr class="testo">
                    <th scope="row">-</th>
                    <th scope="row">-</th>
                      </tr>
                      <tr class="testo">
                    <th scope="row">-</th>
                    <th scope="row">-</th>
                    </tr>
                      <tr class="testo">
                    <th scope="row">[url="?page=adduser&username=<?php echo $username?>&password=<?php echo $password?>"]Aggiungi un'user[/url]</th>
                    <th scope="row">[url="?page=edituser&username=<?php echo $username?>&password=<?php echo $password?>"]Modifica un'user[/url]</th>
                      </tr>
                      <tr class="testo">
                    <th scope="row">[url="?page=edituser&username=<?php echo $username?>&password=<?php echo $password?>"]Cancella un'user[/url]</th>
                    <th scope="row"></th>
                      </tr>
                    <?php 
                

                
    ?>
                </table>
                <?php
            
    }
        }

    ma purtroppo non va lo stesso.

    Ho postato tutto il listato con tutte le graffe...........

    PS: se faccio un echo $SERVER["PHP_SELF"]; dopo l'include all'inizio, non mi esce niente. Non capisco....

  10. #10
    La variabile è $_SERVER non $SERVER e se nel form usi il metod="post" devi usarlo anche in php usando $_POST invece di $_GET.
    Usa questo:
    Codice PHP:
    <?php
    //////////////// /Admin/index.php
    /////////// Nius Pro.
    include("../config.php");
    ?>
    <link href="../nius_chimeralabs.css" rel="stylesheet" type="text/css">
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th class="titolone" scope="row"><span class="Stile1">nius<span class="Stile2">:pro </span></span></th>
      </tr>
    </table>


    <?php
      
    if(!isset($_POST['page']))
    {
    ?>
    <form name="form1" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
        <input type="hidden" name="page" value="menu">
      <table width="100%"  border="0" cellspacing="3" cellpadding="0">
        <tr>
          <th width="34%" class="testo" scope="row"><div align="right">username</div></th>
          <td width="50%"><input name="username" type="text" class="poster"></td>
        </tr>
        <tr>
          <th class="testo" scope="row"><div align="right">password</div></th>
          <td><input name="password" type="password" class="poster"></td>
        </tr>
        <tr>
          <th colspan="2" class="testo" scope="row"><input name="Submit" type="submit" class="poster" value="Invia">
          </th>
        </tr>
      </table>
    </form>
    <?php
    }
    elseif(
    $_POST['page'] == "menu")

        {
            unset(
    $_POST['page']);
            
    define("CONNESSIONE",true);
            
    define("ADMINISTRATION"true);
            
    define("USER_READ"true);
            include(
    "../config.php");
            
    $row mysql_num_rows($iea);
            if(
    $row)
            {
                
    $risultato mysql_fetch_array($iea);
                
    ?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                <th colspan="2" class="poster" scope="row">Benvenuto: <?php echo $risultato["username"]; ?></th>
                  </tr>
                  <tr class="testo"><?php $username $risultato["username"]; $password $risultato["password"]; ?>
                <th scope="row">[url="?page=newsadd&username=<?php echo $username?>&password=<?php echo $password?>"]Aggiungi una news[/url]</th>
                   <th scope="row">[url="?page=newsedit&username=<?php echo $username?>&password=<?php echo $password?>"]Modifica Una News[/url]</th>
                </tr>
                  <tr class="testo">
                <th scope="row">[url="?page=newsedit&username=<?php echo $username?>&password=<?php echo $password?>"]Elimina una news[/url]</th>
                <th scope="row">-</th>
                  </tr>
                <?php
                
    if($risultato["livello"] == "0")
                {
                    
    ?>
                    <tr class="testo">
                    <th scope="row">-</th>
                    <th scope="row">-</th>
                      </tr>
                      <tr class="testo">
                    <th scope="row">-</th>
                    <th scope="row">-</th>
                    </tr>
                      <tr class="testo">
                    <th scope="row">[url="?page=adduser&username=<?php echo $username?>&password=<?php echo $password?>"]Aggiungi un'user[/url]</th>
                    <th scope="row">[url="?page=edituser&username=<?php echo $username?>&password=<?php echo $password?>"]Modifica un'user[/url]</th>
                      </tr>
                      <tr class="testo">
                    <th scope="row">[url="?page=edituser&username=<?php echo $username?>&password=<?php echo $password?>"]Cancella un'user[/url]</th>
                    <th scope="row"></th>
                      </tr>
                    <?php
                
    }
                
    ?>
                </table>
                <?php
            
    }
        }
    Non l'ho testato ma dovrebbe andare
    Coltiva Linux, Windows si pianta da solo!

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.