Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    problemi con le funzioni

    codice HTML:
    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta charset="utf-8">
             <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <link href="config.css" type="text/css" rel="stylesheet">
        </head>
    
        <body onload="loadDoc()">
    
            <div id="form-riconoscimento">
                <h4>modulo di riconoscimento</h4>
                    <table>
                        <form method="get" action="server.php">
    
                            <tr>
                                <td><input type="text" name="username" placeholder="username"></td>
                            </tr>    
                            <tr>    
                                <td><input type="password" name="password" placeholder="password"></td>
                            </tr>
                            <tr>
                                <td><input type="radio" name="opzioneUtente" value="registrareUtente">registrasi</td></tr>
                            <tr>
                                <td><input type="radio" name="opzioneUtente" value="loggareUtente">accedere</td>
                            </tr>
                            <tr>
                                <td><input type="submit" value="invio"></td></tr>
                        </form>
                    </table>
            </div>
    <!--
            <p id="demo"></p>
    
            <button onclick="nuovoUtente()" id="IngressoChat">entra in chat</button>
            <button onclick="uscire()" id="uscitaChat">uscire</button>
            <div id="body"></div>
    
            <div id="form">
                  <form method="get" action="server.php">
                      <input type="text" name="mex">
                      <input type="submit" value="invio">
                </form>
            </div>
    
    </body>
    </html>
    Codice PHP:
    <?php
    session_start
    ();
    $conex mysql_connect('localhost''root');
    mysql_select_db("my_laboraccio"$conex);
    $uname $_GET['username'];
    $pw =  $_GET['password'];
    $opzioneUtente $_GET['opzioneUtente'];
    echo 
    $opzioneUtente;
    echo 
    $uname;
    echo 
    $pw;
    echo 
    gettype($opzioneUtente);
    if(
    $opzioneUtente == 'registrareUtente'){
        function 
    registraUtente(){
            
    $sql "SELECT * FROM utenti WHERE username='$uname'";
            
    $resource mysql_query($sql) or die (mysql_error());
            
    $result mysql_num_rows($resource);
            echo 
    $result;
            if(
    $result == 0) {
                
    $sql "INSERT INTO utenti (id, username, password) VALUES (NULL, '$uname', '$pw')";
                
    mysql_query($sql);
                
    header("Refresh:10; url=http://www.laboraccio.altervista.org/");
                  echo 
    "nuovo utente creato";
     
                echo 
    "registrazione completata";
            }
            elseif(
    $result == 1){
                echo 
    "username gia in uso, riprova con un altro";
                  
    header("Refresh:10; url=http://www.laboraccio.altervista.org/");
               }
        }
    }
    elseif(
    $opzioneUtente == "loggareUtente") {
        function 
    loggareUtente(){
            
    $sql "SELECT * FROM utenti WHERE username='$uname' AND password='$pw'";
            
    $resource mysql_query($sql) or die (mysql_error());
            
    $result mysql_num_rows($resource);
            if(
    $result == 1) {
                
    $_SESSION['username'] = $uname;
                
    $_SESSION['password'] = $pw;
            echo 
    "benvenuto alla tua area personale".$uname;
            
            }

        
        }
    }

    ?>
    SITO www.laboraccio.altervista.org
    non capisco perche le funzioni non vanno

  2. #2
    Utente di HTML.it L'avatar di boots
    Registrato dal
    Oct 2012
    Messaggi
    1,626
    Perchè non le richiami.
    Codice PHP:
    function registraUtente(){
        ...

    E' solo la dichiarazione. Poi va anche chiamata.
    Per questo quello che hai scritto, non è corretto ne "bello".
    Dovresti fare una cosa del genere:
    Codice PHP:
    function registraUtente(){
       ....
    }
    function 
    loggareUtente(){
      .....
    }
    session_start();
    $connex 
    ....
    if(
    $optiozioneUtente == 'registraUtente'){
        
    regitraUtente(); // Richiami la funzione
    }elseif($optzioniUtente == 'loggareUtente'){
       
    loggareUtente();

    cmq se le funzioni le usi solo qui ha poco senso crearle invece che scrivere il codice direttamente negli if

  3. #3
    grazie boots, pensavo la stessa cosa ma non ero completamente sicuro, perche alcune volte in altri codici le funzioni mi andavano anche cosi senza richiarmarle.

Tag per questa discussione

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 © 2024 vBulletin Solutions, Inc. All rights reserved.