Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Sprawdzanie poprawności danych w Mysql i wyświetlanie różnych formularzy
Forum PHP.pl > Forum > Przedszkole
Cherob
Cześć chcę aby po przekazaniu zmiennej URl index.php?id=użytkownik wyświetlały się dwa różne formularze w zależności od podania prawidłowej nazwy użytkownika i nie. Możecie mi powiedzieć co tu nie gra w tym skrypcie i jak to naprawić.
  1. <?php
  2.  
  3. $id=$_POST['id'];
  4.  
  5. $host=""; // Host name
  6. $username=""; // Mysql username
  7. $password=""; // Mysql password
  8. $db_name=""; // Database name
  9. $tbl_name="yet"; // Table name
  10.  
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14. $sql="SELECT * FROM $tbl_name WHERE username='$id'";
  15. $result=mysql_query($sql);
  16.  
  17.  
  18. $count=mysql_num_rows($result);
  19.  
  20.  
  21. if($count==1){
  22. <form action="rejestruj.php" method="post"
  23. <tr>
  24. <th>Email: </th>
  25. <td><input name="fname" type="text" valu="" /></td>
  26. </tr>
  27. <input type="submit" name="Wyślij"></form>';
  28. }
  29. else {
  30. <form action="index.php" method="post"
  31. <tr>
  32. <th>Wprowadź nazwę użytkownika: </th>
  33. <td><input name="fname" type="text" valu="" /></td>
  34. </tr>
  35. <input type="submit" name="Wyślij"></form>';
  36. }
  37. ?>
lukasz91
Zapewne błąd w zapytaniu. Daj:
  1. if(!$result) {
  2. }
Cherob
Czemu gdy przez formularz wysyłam dane wszystko działa a gdy próbuję przez przeglądarkę wpisując checklogin.php?myusername=john już nie

  1. <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  2. <tr>
  3. <form name="form1" method="post" action="checklogin.php">
  4. <td>
  5. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  6. <tr>
  7. <td colspan="3"><strong>Member Login </strong></td>
  8. </tr>
  9. <tr>
  10. <td width="78">Username</td>
  11. <td width="6">:</td>
  12. <td width="294"><input name="myusername" type="text" id="myusername"></td>
  13. </tr>
  14. <tr>
  15. <td>&nbsp;</td>
  16. <td>&nbsp;</td>
  17. <td><input type="submit" name="Submit" value="Login"></td>
  18. </tr>
  19. </td>
  20. </form>
  21. </tr>
  22. </table>

checklogin.php
  1. <?php
  2. $host="mysql.cba.pl"; // Host name
  3. $username="gebit"; // Mysql username
  4. $password="55845555"; // Mysql password
  5. $db_name="donaukiphp_cba_pl"; // Database name
  6. $tbl_name="yet"; // Table name
  7.  
  8.  
  9. $zmienna1='<form action="index.php" method="post"
  10. <tr>
  11. <th>Wprowadź urzytkownika: </th>
  12. <td><input name="fname" type="text" valu="" /></td>
  13. </tr>
  14. <input type="submit" name="Wyślij"></form>';
  15.  
  16. $zmienna2='<form action="index.php" method="post"
  17. <tr>
  18. <th>Wprowadź nazwę urzytkownika: </th>
  19. <td><input name="fname" type="text" valu="" /></td>
  20. </tr>
  21. <input type="submit" name="Wyślij"></form>';
  22.  
  23.  
  24. // Connect to server and select databse.
  25. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  26. mysql_select_db("$db_name")or die("cannot select DB");
  27.  
  28. // Define $myusername and $mypassword
  29. $myusername=$_POST['myusername'];
  30.  
  31. // To protect MySQL injection (more detail about MySQL injection)
  32. $myusername = stripslashes($myusername);
  33. $myusername = mysql_real_escape_string($myusername);
  34.  
  35.  
  36. $sql="SELECT * FROM $tbl_name WHERE username='$myusername'";
  37. $result=mysql_query($sql);
  38.  
  39. // Mysql_num_row is counting table row
  40. $count=mysql_num_rows($result);
  41. // If result matched $myusername and $mypassword, table row must be 1 row
  42.  
  43. if($count==1){
  44.  
  45. session_register("myusername");
  46. echo "$zmienna1";
  47. }
  48. else {
  49. echo "$zmienna2";
  50. }
  51.  
  52. ?>
nospor
Bo w kodzie dane odbierasz z $_POST,a to co wstawiasz w linku to $_GET.

ps: przenosze
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.