Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27

    Non capisco perchè.......

    buongiorno ho un problema con questo codice:

    Codice PHP:
    <?php
    include('dati.php');
    session_start();
      
    $link=mysql_connect("$databaseHostName","$databaseUserName","$databaseUserPassword")
           or die (
    "Non riesco a connettermi a $databaseHostName");
           
    mysql_select_db ($databaseName$link)
           or die (
    "Non riesco a selezionare il db $databaseName<br>");
    ?>
     <form action='' method='post'>
       <tr>
       <td>Tipo di richiesta</td>
       <td>:</td>
        <td><input type='radio' name='btn_submit' value='1'  onclick='this.form.submit();'>Intervento  Tecnico</input></td>
       <td><input type='radio'  name='btn_submit' value='2' onclick='this.form.submit();'>Materiale  di consumo</input></td>
       <td><input  type='radio' name='btn_submit' value='3'  onclick='this.form.submit();'>HW/SW aggiuntivo  </input></td>
     <?php   
     $btn_submit 
    $_POST['btn_submit'];    //linea 78
     
    $_SESSION['btn_submit'] = $btn_submit;
       
     if (
    $btn_submit=='1')
       {
          echo 
    "<textarea name='comments' cols='105' rows='9'>richiesta intervento tecnico...</textarea><br>";
       }
     if (
    $btn_submit=='2')
       {
          
    $RMC "SELECT marca,matricola FROM materiali";
          
    mysql_query($RMC) or die (mysql_error());
          echo 
    "<table  width='600px' align='center' border='1' bgcolor='#CCFFFF'>
                                    <tr>
                                    <th>Marca</th>
                                    <th>Matricola</th>
                                   </tr>"
    ;
                            while(
    $row mysql_fetch_array($RMC))   //linea 94
                            
    {
                            echo 
    "<tr>";
                            echo 
    "<td>" $row['marca'] . "</td>";
                            echo 
    "<td>" $row['matricola'] . "</td>";
                            }
       }            
       
     if (
    $btn_submit=='3')
       {   
          echo 
    "<textarea name='comments' cols='105' rows='9'>richiesta HW/SW aggiuntivo...</textarea><br>";
       }
     
    ?>
    </tr>
    di seguito un tail del /var/log/httpd/error.log

    codice:
    [Thu Jun 05 11:30:29 2014] [error] [client 127.0.0.1] PHP  Notice:  Undefined index: btn_submit in /var/www/html/personale.php on  line 78
    [Thu Jun 05 11:30:33 2014] [error] [client 127.0.0.1] PHP  Warning:  mysql_fetch_array() expects parameter 1 to be resource, string  given in /var/www/html/personale.php on line 94, referer:  http://127.0.0.1/personale.php

    Infine i Dati relativi al sistema:

    S.O. Centos 6.5
    php-5.3.3-27.el6_5.x86_64
    httpd-2.2.15-29.el6.centos.x86_64
    mysql-5.1.73-3.el6_5.x86_64

    spero possiate essermi d'aiuto, grazie.


  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    La prima volta che arrivi sulla pagina $_POST non è inizializzato, quindi non lo puoi usare, dovresti testarlo con
    Codice PHP:
    if isset($_POST['btn_submit'])
    {
        
    $btn_submit $_POST['btn_submit'];
        ...
    }
    else
    {
        
    //è la prima volta che arrivi sulla pagina


  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27
    Ho provato il risultato è:
    [Thu Jun 05 14:10:09 2014] [error] [client 127.0.0.1] PHP Notice: Undefined index: btn_submit in /var/www/html/personale.php on line 78
    [Thu Jun 05 14:10:17 2014] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected T_ISSET, expecting '(' in /var/www/html/test.php on line 20

    il $_POST dovrebbe farmelo sulla stessa pagina e non mi raccapezzo

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Scusa, mi sono dimenticato un paio di parentesi

    if (isset($_POST['btn_submit']))

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27
    un'altra stranezza (per me autodidatta!) è che se metto un "else", dopo il primo "if" del mio codice iniziale, mi dice che non si aspetta la "{"
    Perchè? Mha!
    E' possibile che ci siano problemi con il mio php?

  6. #6
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    No, c'è un errore nel codice.
    Posta il codice che hai ora.

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27
    Il codice :
    Codice PHP:
    <form action='' method='post'>
        <tr>
        <td>Tipo di richiesta</td>
        <td>:</td>
        <td><input type='radio' name='btn_submit' value='1' onclick='this.form.submit();'>Intervento Tecnico</input></td>
        <td><input type='radio' name='btn_submit' value='2' onclick='this.form.submit();'>Materiale di consumo</input></td>
        <td><input type='radio' name='btn_submit' value='3' onclick='this.form.submit();'>HW/SW aggiuntivo </input></td>
    <?php    
    if (isset($_POST['btn_submit'])) 
    {
        
    $btn_submit $_POST['btn_submit'];

    }
    $_SESSION['btn_submit'] = $btn_submit;
        
    if (
    $btn_submit=='1')
        {
            echo 
    "<textarea name='comments' cols='105' rows='9'>richiesta intervento tecnico...</textarea><br>";
        }
    if (
    $btn_submit=='2')
        {
            
    $RMC "SELECT marca,matricola FROM materiali";
            
    mysql_query($RMC) or die (mysql_error());
            echo 
    "<table  width='600px' align='center' border='1' bgcolor='#CCFFFF'>
                                    <tr>
                                    <th>Marca</th>
                                    <th>Matricola</th>
                                   </tr>"
    ;
                            while(
    $row mysql_fetch_array($RMC))
                            {
                            echo 
    "<tr>";
                            echo 
    "<td>" $row['marca'] . "</td>";
                            echo 
    "<td>" $row['matricola'] . "</td>";
                            }
        }            
        
    if (
    $btn_submit=='3')
        {    
            echo 
    "<textarea name='comments' cols='105' rows='9'>richiesta HW/SW aggiuntivo...</textarea><br>";
        }
    ?>
    </tr>
    l'errore:
    codice:
    [Thu Jun 05 14:30:24 2014] [error] [client 127.0.0.1] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, string given in /var/www/html/personale.php on line 98, referer: http://127.0.0.1/personale.php

  8. #8
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27
    Se sostituisco i vari "if" con "else" o "elseif" mi dice che non si aspetta la "{"

  9. #9
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Fammi vedere come fai la sostituzione, è inutile se mi mostri il codice che funziona e non quello che ha problemi.

  10. #10
    Utente di HTML.it
    Registrato dal
    Jun 2014
    Messaggi
    27
    ma già con questo di codice ho problemi se seleziono il radio con valore 2 mi restituisce il warning che ti ho riportato sopra.

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