Sto facendo i miei primi passi alla programmazione ed ho bisogno del vostro aiuto. Ho creato un semplice database e visualizza i risultati da un unica tabella rispetto a chi fa il login. Voglio aggiungere anche la funzione cerca ma mi manca solo un passaggio. Siccome la ricerca non deve essere effettuata in intera tabella ma solo alla voci che l'utente puo vedere vorrei trasferire il nickname del utente nel file search.php. Spero che sono stato chiaro (scusatemi per eventuali errori grammaticali,non sono italiano,per questo resto a disposizione per qualsiasi chiarimento)

il primo file è il login.php con la semplice form per l'accesso.
Codice PHP:
<body>     <div align="center"> [img]http:/....[/img] </img> </div>
          <
div class="divlog">     <form id="form" name="form" method="post" action="index.php">  Nome Utente:     <input name="username" type="text" size="32" maxlength="32" />
 
Password:          <input name="password" type="password" size="32" maxlength="32" />
     <
input name="Log In" type="submit" value="Log In" /> </form> </div>  </body
il file validation.php dove chiaramente fa il controllo dati
Codice PHP:
<?php include 'connection.php'//STEP 2 Declare Variables  $Name = $_POST['username']; $Pass = $_POST['password']; $Query = mysql_query("SELECT * FROM users WHERE username='$Name' AND password='$Pass'"); $NumRows = mysql_num_rows($Query); $_SESSION['username'] = $Name; $_SESSION['password'] = $Pass;  //STEP 3 Check to See If User Entered All Of The Information  if(empty($_SESSION['username']) || empty($_SESSION['password'])) { die("Fare il [url="login.php>login</a>"]"); }  if($Pass == "") { die("Per favore inserisci una password!"); echo "</br>"; }  //STEP 4 Check Username And Password With The MySQL Database  if($NumRows != 0) { while($Row = mysql_fetch_assoc($Query)) { $Database_Name = $Row['username']; $Database_Pass = $Row['password']; } } else { die("Incorrect Username or Password! <a href=login.php>Riprovare[/url]"); }  //if($Name == $Database_Name && $Pass == $Database_Pass) //{ // If The User Makes It Here Then That Means He Logged In Successfully //echo "Benvenuto " . $_SESSION['username'] . "!"; //} ?>
il file index.php dove alla fine del file ho inserito la forma per la ricerca
Codice PHP:
<?php  include 'validation.php';  $client_nickname=$_POST['username']; $tab_macchinari='apparecchi'$tab_clienti='aziende';  $query_name="SELECT * FROM $tab_clienti WHERE user='$client_nickname'"$name_c=mysql_query($query_name); $row_namemysql_fetch_assoc($name_c); $row_name_d=$row_name['Nome_Ditta']; $row_cognome=$row_name['Titolare']; $row_telefono=$row_name['Telefono']; $row_fax=$row_name['Fax']; $row_indirizzo=$row_name['Indirizzo']; $row_sito=$row_name['Sito Web'];    $query="SELECT * FROM $tab_macchinari WHERE ditta='$row_name_d'"$loop mysql_query($query)    or die (mysql_error());  $count="SELECT COUNT(*) FROM $tab_macchinari WHERE ditta='$row_name_d'"$count_q=  mysql_query($count); $count_num=mysql_result($count_q,0);   echo "<div class='conteiner'>   <div id='left'>    <table class='curvedEdges' cellspacing='0px'>   <tr>     <th colspan='2' scope='col'>$row_name_d</th>   </tr>   <tr>     <th scope='row'>Titolare</th>     <td align=\"center\">$row_cognome</td>   </tr>   <tr>     <th scope='row'>Telefono</th>     <td align=\"center\">$row_telefono</td>   </tr>   <tr>     <th scope='row'>Fax</th>     <td align=\"center\">$row_fax</td>   </tr>   <tr>     <th scope='row'>Indirizzo</th>     <td align=\"center\">$row_indirizzo</td>   </tr>   <tr>     <th scope='row'>Sito web</th>     <td align=\"center\"><a href=\"http://$row_sito\">$row_sito</a></td>   </tr> </table>  </div>      <div id='right'> [img]http://...[/img] </img> </div>      <div id='bottom'> <font-size:12px>*</font>    <table class='curvedEdges' cellspacing='0px'>           <caption>ELENCO $row_name_d</caption>              <thead>              <tr>                 <th>Tipologia</th>                 <th>Costruttore</th>                 <th>Anno Costruzione</th>                 <th>Portata</th>                 <th>Matricola Enpi</th>                 <th>Fabbricazione</th>                 <th>Ultima Verifica</th>                 <th>Durata Anni</th>                 <th>Prossima Verifica</th>                 <th>Ultima Verifica Straordinaria</th>                 <th>Frequenza Anni</th>                 <th>Prossima Verifica Straordinaria</th>              </tr>               </thead>               <tfoot>                 <tr>                  <td align='right' >Prodotti Totali: $count_num </td>                   </tr>                 </tfoot>";   while ($row mysql_fetch_array($loop)) {      $tipologia=$row['tipologia'];      $costruttore=$row['costruttore'];      $annocostruzione=$row['anno_costruzione'];      $portata=$row['portata'];      $matricolaenpi=$row['matricola_ENPI'];      $fabbric=$row['fabbric'];      $ultimaverifica=$row['ultima_verifica'];      $durataanni=$row['durata_anni'];      $prossimaverifica=$row['prossima_verifica'];      $ultimaverificstrd=$row['ultima_verifica_straordinaria'];      $frequenzanni=$row['frequenza_anni'];      $prosverifstrd=$row['prossima_verifica_straordinaria'];  $today=strtotime(date('Y-m-d',time())); $expire strtotime($prossimaverifica); $diff=$expire-$today//diff σε δευτερόλεπτα. //$daySecs=86400;//Μια μέρα έχει 86400 secs   //echo "$diff ";   if ($diff<=2592000) $highlightclass="red";  elseif ($diff>2592000 && $diff<15552000) $highlightclass="yellow";   else $$highlightclass="";          echo "<tbody>   <tr class='alt'>   <td align=\"center\" >$tipologia</td>   <td align=\"center\">$costruttore</td>   <td align=\"center\" >$annocostruzione</td>   <td align=\"center\" >$portata</td>   <td align=\"center\" >$matricolaenpi</td>   <td align=\"center\" >$fabbric</td>   <td align=\"center\" >$ultimaverifica</td>   <td align=\"center\" >$durataanni</td>   <td bgcolor=$highlightclass >$prossimaverifica</td>   <td align=\"center\" >$ultimaverificstrd</td>   <td align=\"center\" >$frequenzanni</td>   <td align=\"center\" >$prosverifstrd</td>   </tr></div>";            }  ?> <form  method="post" action="search.php?go"  id="searchform">         <input  type="text" name="name">       <input  type="submit" name="submit" value="Cerca">     </form> </body> </html>
e alla fine il file search.php dove io ho bisogno che al posto della variabile $cliente_nickname va al leggere il username di chi ha effettuato l'accesso.
Codice PHP:
<?php include 'connection.php';     if(isset($_POST['submit'])){   if(isset($_GET['go'])){   if(preg_match("/^[  a-zA-Z]+/"$_POST['name'])){   $name=$_POST['name'];        //-query  the database table   $query_name="SELECT * FROM aziende WHERE user='$cliente_nickname'";   $name_c=mysql_query($query_name);   $row_name= mysql_fetch_assoc($name_c);   $row_name_d=$row_name['Nome_Ditta'];   $sql="SELECT  * FROM apparecchi WHERE ditta='$row_name_d' AND tipologia LIKE '%" . $name .  "%' OR costruttore LIKE '%" . $name ."%' OR portata LIKE '%" . $name ."%' OR matricola_ENPI LIKE '%" . $name ."%' OR fabbric LIKE '%" . $name ."%'";   //-run  the query against the mysql querFirstNamey function   $result=mysql_query($sql);      echo "<table  cellspacing='1px' border='1px'>              <thead>              <tr>                 <th>Tipologia</th>                 <th>Costruttore</th>                 <th>Anno Costruzione</th>                 <th>Portata</th>                 <th>Matricola Enpi</th>                 <th>Fabbricazione</th>                 <th>Ultima Verifica</th>                 <th>Durata Anni</th>                 <th>Prossima Verifica</th>                 <th>Ultima Verifica Straordinaria</th>                 <th>Frequenza Anni</th>                 <th>Prossima Verifica Straordinaria</th>              </tr>               </thead>               <tfoot>                 <tr>                                  </tr>                 </tfoot>";    //-create  while loop and loop through result set   while($row=mysql_fetch_array($result)){            $tipologia=$row['tipologia'];      $costruttore=$row['costruttore'];      $annocostruzione=$row['anno_costruzione'];      $portata=$row['portata'];      $matricolaenpi=$row['matricola_ENPI'];      $fabbric=$row['fabbric'];      $ultimaverifica=$row['ultima_verifica'];      $durataanni=$row['durata_anni'];      $prossimaverifica=$row['prossima_verifica'];      $ultimaverificstrd=$row['ultima_verifica_straordinaria'];      $frequenzanni=$row['frequenza_anni'];      $prosverifstrd=$row['prossima_verifica_straordinaria'];    //-display the result of the array   echo "<tbody>   <tr class='alt'>   <td align=\"center\" >$tipologia</td>   <td align=\"center\">$costruttore</td>   <td align=\"center\" >$annocostruzione</td>   <td align=\"center\" >$portata</td>   <td align=\"center\" >$matricolaenpi</td>   <td align=\"center\" >$fabbric</td>   <td align=\"center\" >$ultimaverifica</td>   <td align=\"center\" >$durataanni</td>   <td align=\"center\">$prossimaverifica</td>   <td align=\"center\" >$ultimaverificstrd</td>   <td align=\"center\" >$frequenzanni</td>   <td align=\"center\" >$prosverifstrd</td>   </tr></div>";   }   }   else{   echo  "

Please enter a search query</p>";   }   }   } ?>