Advertisement
Guest User

Untitled

a guest
May 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. $yhteys = mysql_connect("localhost", "root", "")
  4. or die("Yhteys ei onnistunut. ".mysql_error());
  5. mysql_select_db("testikanta2",$yhteys)
  6. or die("Kantaa ei löytynyt. ".mysql_error());
  7.  
  8. $tulos = mysql_query("SELECT * FROM firma", $yhteys);
  9.  
  10.  
  11.  
  12. while($tulosrivi = mysql_fetch_array($tulos)){
  13. echo $tulosrivi['nimi']." ".$tulosrivi['osoite']."<br>";
  14. }
  15. echo "<br>-----------<br>";
  16. ?>
  17.  
  18. <?php
  19. $firmahaku = $_POST["firma"];
  20.  
  21. if (!isset($_POST['nappi'])) { // if page is not submitted to itself echo the form
  22. ?>
  23.  
  24. <form method="post" action="<?php echo $PHP_SELF;?>">
  25. <p>
  26. <label for="nimi">Firma: </label>
  27. <input id="nimi" type="text" name="firma" size="50" />
  28. </p>
  29.  
  30. <p>
  31. <input type="submit" name="nappi" value="Etsi" />
  32. </p>
  33. </form>
  34.  
  35. <?php
  36. } else {
  37.  
  38. $haku = mysql_query("SELECT * FROM firma WHERE nimi like '$firmahaku'", $yhteys);
  39. echo "Haettu firma<br>";
  40. while($tulosrivi = mysql_fetch_array($haku)){
  41. echo $tulosrivi['nimi']." ".$tulosrivi['osoite']."<br>";
  42. }
  43. echo "<br>-----------<br>";
  44.  
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement