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

    [PHP] Problema Contollo campi

    Ciao,

    ho un piccolo problema che non é grave ma se si puo risolvere sarebbe bello, mi spiego;
    quando tento di inserire dati nel db se non inserisco niente nei campi mi da il messaggio di errore giusto, se li compilo tutti me inserisce senza problemi, il problema sta quando per esempio compilo solo il primo campo e poi inserisco, ecco io qui non vorrei che si inserisce solo compilando il primo campo, ma vorrei che se lutente compila solo il primo campo mi da il messaggio di errore compilare tutti i campi, il mio codice é il seguente;

    Codice PHP:
    <?php 
    $currentDate 
    date("d/m/Y");

    if (isset(
    $_POST['Submit'])
        and empty(
    $_POST['call_callsign'])
        and empty(
    $_POST['call_sTime'])
        and empty(
    $_POST['call_reportOut'])
        and empty(
    $_POST['call_reportIn'])
        and empty(
    $_POST['call_remarks'])
        and empty(
    $_POST['call_user'])
        and empty(
    $_POST['call_qslIn'])
        and empty(
    $_POST['call_qslOut'])) {
            
    $msg "Inserire tutti i campi";
    } else {
        
        
        
        
        

    if(isset(
    $_POST['Submit']) && $_GET['action'] == "insert") {
    mysql_select_db($database_name$conn) or die (mysql_error());
    $query "INSERT INTO tb_contact (call_callsign, call_date, call_sTime, call_band, call_mode, call_power, call_reportOut, call_reportIn, call_remarks, call_user, call_qslIn, call_qslOut, call_contest) VALUES ( '".$_POST['call_callsign']."',
                                                                             '"
    .$_POST['call_date']."',
                                                                             '"
    .$_POST['call_sTime']."',
                                                                             '"
    .$_POST['call_band']."',
                                                                             '"
    .$_POST['call_mode']."',
                                                                             '"
    .$_POST['call_power']."',
                                                                             '"
    .$_POST['call_reportOut']."',
                                                                             '"
    .$_POST['call_reportIn']."',
                                                                             '"
    .$_POST['call_remarks']."',
                                                                             '"
    .$_POST['call_user']."',
                                                                             '"
    .$_POST['call_qslIn']."',
                                                                             '"
    .$_POST['call_qslOut']."',
                                                                             '"
    .$_POST['call_contest']."'
                                                                            )"
    ;
    mysql_query($query);
    $msg "Contatto aggiunto correttamente";
    }
    }

    ?>
    Grazie Michel
    PHP THE BEST

  2. #2
    hai pensato ad inserire OR invece che AND nell'IF?
    "Una volta che si saranno esaurite senza successo tutte le possibilita', ci sara' una soluzione, semplice e ovvia, che saltera' immediatamente all'occhio di chiunque altro."

    Guardate: Il Miracolo delle Noci!!

  3. #3
    ho provato a mettere or al posto di and, adesso però mi dice subito il messaggio inserire tutti i campi, poi anche se li compilo tutti mi dice sempre inserire tutti i campi!! Help!!!

    Codice PHP:
    <?php 
    $currentDate 
    date("d/m/Y");

    if (isset(
    $_POST['Submit'])
        or empty(
    $_POST['call_callsign'])
        or empty(
    $_POST['call_sTime'])
        or empty(
    $_POST['call_reportOut'])
        or empty(
    $_POST['call_reportIn'])
        or empty(
    $_POST['call_remarks'])
        or empty(
    $_POST['call_user'])
        or empty(
    $_POST['call_qslIn'])
        or empty(
    $_POST['call_qslOut'])) {
            
    $msg "Inserire tutti i campi";
    } else {
        
        
        
        
        

    if(isset(
    $_POST['Submit']) && $_GET['action'] == "insert") {
    mysql_select_db($database_name$conn) or die (mysql_error());
    $query "INSERT INTO tb_contact (call_callsign, call_date, call_sTime, call_band, call_mode, call_power, call_reportOut, call_reportIn, call_remarks, call_user, call_qslIn, call_qslOut, call_contest) VALUES ( '".$_POST['call_callsign']."',
                                                                             '"
    .$_POST['call_date']."',
                                                                             '"
    .$_POST['call_sTime']."',
                                                                             '"
    .$_POST['call_band']."',
                                                                             '"
    .$_POST['call_mode']."',
                                                                             '"
    .$_POST['call_power']."',
                                                                             '"
    .$_POST['call_reportOut']."',
                                                                             '"
    .$_POST['call_reportIn']."',
                                                                             '"
    .$_POST['call_remarks']."',
                                                                             '"
    .$_POST['call_user']."',
                                                                             '"
    .$_POST['call_qslIn']."',
                                                                             '"
    .$_POST['call_qslOut']."',
                                                                             '"
    .$_POST['call_contest']."'
                                                                            )"
    ;
    mysql_query($query);
    $msg "Contatto aggiunto correttamente";
    }
    }

    ?>
    Grazie michel
    PHP THE BEST

  4. #4
    credo che il primo OR dovesse rimanere un AND perchè ovvio che se tu invii il form per lo script attuale la condizione di errore srà sempre soddisfatta.
    "Una volta che si saranno esaurite senza successo tutte le possibilita', ci sara' una soluzione, semplice e ovvia, che saltera' immediatamente all'occhio di chiunque altro."

    Guardate: Il Miracolo delle Noci!!

  5. #5
    Si mettendo and funziona correttamente solo che come detto vorrei che se l'utente per esmpio dimentica un campo mi dica inserire tutti i campi, e non che me lo inserisca ugualmente nel db con un campo vuoto!!

    Se qualcuno é cosi gentile da correggermi il codice sarebbe magnifico!!

    Grazie Michel
    PHP THE BEST

  6. #6
    azz ma un pò di inventiva... uff:
    Codice PHP:
    <?php
    $currentDate 
    date("d/m/Y");

    if (isset(
    $_POST['Submit'])) {
      if (empty(
    $_POST['call_callsign'])
        or empty(
    $_POST['call_sTime'])
        or empty(
    $_POST['call_reportOut'])
        or empty(
    $_POST['call_reportIn'])
        or empty(
    $_POST['call_remarks'])
        or empty(
    $_POST['call_user'])
        or empty(
    $_POST['call_qslIn'])
        or empty(
    $_POST['call_qslOut']))
      {
            
    $msg "Inserire tutti i campi";
      } else
      {
        if(isset(
    $_POST['Submit']) && $_GET['action'] == "insert")
        {
          
    mysql_select_db($database_name$conn) or die (mysql_error());
          
    $query "INSERT INTO tb_contact (call_callsign, call_date, call_sTime, call_band, call_mode, call_power, call_reportOut, call_reportIn, call_remarks, call_user, call_qslIn, call_qslOut, call_contest) VALUES ( '".$_POST['call_callsign']."',
                                                                             '"
    .$_POST['call_date']."',
                                                                             '"
    .$_POST['call_sTime']."',
                                                                             '"
    .$_POST['call_band']."',
                                                                             '"
    .$_POST['call_mode']."',
                                                                             '"
    .$_POST['call_power']."',
                                                                             '"
    .$_POST['call_reportOut']."',
                                                                             '"
    .$_POST['call_reportIn']."',
                                                                             '"
    .$_POST['call_remarks']."',
                                                                             '"
    .$_POST['call_user']."',
                                                                             '"
    .$_POST['call_qslIn']."',
                                                                             '"
    .$_POST['call_qslOut']."',
                                                                             '"
    .$_POST['call_contest']."'
                                                                            )"
    ;
          
    mysql_query($query);
          
    $msg "Contatto aggiunto correttamente";
        }
      }
    }
    ?>
    "Una volta che si saranno esaurite senza successo tutte le possibilita', ci sara' una soluzione, semplice e ovvia, che saltera' immediatamente all'occhio di chiunque altro."

    Guardate: Il Miracolo delle Noci!!

  7. #7
    Grazie per la correzione ora funziona come deve!! Non sono ancora molto pratico come hai potuto notare ma sto imparando!! Ti ringrazio per la dritta!
    PHP THE BEST

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.