Jump to content

Recommended Posts

Problem: I have a database with members in a society.

I want to search for one person only (from a form) - perhaps to edit his/hers address etc.

Now I want the result to be shown in the form so I can alter the address there and then send it to the database again for updating.

This i have tried:

<?php 
      //Söker funktionär med namn 
      if(isset($sok)){ 
       
         $query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'"; 
         $result = mysql_query($query); 
         if(!$result){ 
               echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>"; 
            echo "</table></div>"; 
         } 
         else { 
            $line = mysql_fetch_assoc($result); 
            $s_namn = $line['namn']; 
            $s_adress = $line['adress']; 
            $s_postnr = $line['postnr']; 
            $s_ort = $line['ort']; 
            $s_tel = $line['tel']; 
            $s_email = $line['email']; 
         } 
      } 
      // Stänger anslutningen till vår databas 
        mysql_close($connection); 

?>

 

Form:

<form method="post" action="<?=$PHP_SELF?>"> 
  <table> 
    <tr> 
      <td width="128" class="text_12">Namn</td> 
      <td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12">Adress</td> 
      <td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12">Postnr</td> 
      <td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12">Ort</td> 
      <td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12">Telnr</td> 
      <td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12">E-mail</td> 
      <td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td> 
    </tr> 
    <tr> 
      <td class="text_12"> </td> 
      <td> </td> 
    </tr> 
    <tr> 
      <td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td> 
      <td> </td> 
    </tr> 
</table> 
</form>

 

Please help!

Like this you mean (or did I misunderstand you because it doesn´t work...?)

  <?php       
  
  	//Söker funktionär med namn       
  		if(isset($sok)){                 
  		$query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'";          
  		$result = mysql_query($query);          
  
  	if(!$result){                
  		echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>";             
  		echo "</table></div>";          }          
  
  	else {             
  		$line = mysql_fetch_assoc($result);             
  		$s_namn = $line['namn'];             
  		$s_adress = $line['adress'];             
  		$s_postnr = $line['postnr'];             
  		$s_ort = $line['ort'];             
  		$s_tel = $line['tel'];             
  		$s_email = $line['email']; 

	<form method="post" action="<?=$PHP_SELF?>">   
	<table><tr>       
	td width="128" class="text_12">Namn</td><td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td></tr>     
	<tr><td class="text_12">Adress</td><td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td></tr>     
	<tr><td class="text_12">Postnr</td><td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td></tr>     
	<tr><td class="text_12">Ort</td><td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td></tr>     
	<tr><td class="text_12">Telnr</td><td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td></tr>     
	<tr><td class="text_12">E-mail</td><td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td></tr>
	<tr><td class="text_12"> </td><td> </td></tr>
	<tr><td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td><td> </td>
	</tr> </table> 		
	</form>         
	}       
}   

   // Stänger anslutningen till vår databas        
    mysql_close($connection);  
?>

  <?php       
  
     //Söker funktionär med namn       
        if(isset($sok)){                 
        $query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'";          
        $result = mysql_query($query);          
  
     if(!$result){                
        echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>";             
        echo "</table></div>";          }          
  
     else {             
        $line = mysql_fetch_assoc($result);             
        $s_namn = $line['namn'];             
        $s_adress = $line['adress'];             
        $s_postnr = $line['postnr'];             
        $s_ort = $line['ort'];             
        $s_tel = $line['tel'];             
        $s_email = $line['email']; 
      ?>

      <form method="post" action="<?=$PHP_SELF?>">   
      <table><tr>       
      td width="128" class="text_12">Namn</td><td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td></tr>     
      <tr><td class="text_12">Adress</td><td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td></tr>     
      <tr><td class="text_12">Postnr</td><td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td></tr>     
      <tr><td class="text_12">Ort</td><td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td></tr>     
      <tr><td class="text_12">Telnr</td><td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td></tr>     
      <tr><td class="text_12">E-mail</td><td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td></tr>
      <tr><td class="text_12"> </td><td> </td></tr>
      <tr><td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td><td> </td>
      </tr> </table>       
      </form>         
     <?php
      }       
   }   
   
   // Stänger anslutningen till vår databas       
    mysql_close($connection); 
   ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.