Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: rejestracja nowych uzytkownikow
Forum PHP.pl > Forum > PHP
grzybu
witam, mam taki problem jestem laikiem w php a ostatnio w necie znalalem skrypt na rejestracje, tylko ze chcialem go troche zmienic, popierwsze w tabeli dodac kilka kolumn, i tera tabela jest taka
  1. CREATE TABLE `user` (
  2. `id` int(4) UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `username` varchar(32) NOT NULL,
  4. `password` varchar(32) NOT NULL,
  5. `firstaname` text collate latin1_general_ci NOT NULL,
  6. `secondname` text collate latin1_general_ci NOT NULL,
  7. `aboutme` text collate latin1_general_ci NOT NULL,
  8. `level` int(4) NOT NULL DEFAULT '1',
  9. `dateofbirth` date NOT NULL,
  10. PRIMARY KEY (`id`)
  11. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;


no i w tym tutorialu byl ze trzeba zrobic database.php(jestem pewien ze jest dobrze ustawione bo zadne bledy nie wyskakuja) i reg.php no to go próbowałem trochę zmienić pod moja tabele i takie cos mi wyszlo
  1. <?php
  2. require_once 'database.php';
  3. ?>
  4.  
  5. <h1><strong>Register</strong></h1>
  6.  
  7. <form name="register" method="post" action="regcheck.php">
  8. <p>Username*
  9. <input type="text" name="user" id="user">
  10. <br>
  11. <label>
  12. Password*
  13. <input type="password" name="pass" id="pass">
  14. <br />
  15. </label>
  16. First Name*
  17. <input type="text" name="firstname" id="firstname">
  18. <br />
  19. </label>
  20. Second Name*
  21. <input type="text" name="secondname" id="secondname">
  22. <br />
  23. </label>
  24. About Me*
  25. <input type="text" name="aboutme" id="aboutme">
  26. <br />
  27. </label>
  28. Date of Birth(DD/MM/YYYY)*
  29. <input type="date" name="dateofbirth" id="dateofbirth">
  30. <br />
  31. </label>
  32. <label>
  33. <input type="submit" name="reg" id="reg" value="Register">
  34. </label>
  35. </p>
  36. <p>*You need to fill them in.</p>
  37. </form>
  38. <label></label>
  39.  
  40. <form name="Back" method="post" action="Login.php">
  41. <input type="submit" name="back" id="back" value="Back to Home">
  42. <p> </p>


no i potem bylo ze trzeba zrobic regcheck.php, no to tez troche probowalem cos zmienic i tak mi wyszlo
  1. <?php
  2. if(
  3. isset( $_POST['user'] ) &&
  4. isset( $_POST['pass'] ) &&
  5. isset( $_POST['firstname'] ) &&
  6. isset( $_POST['secondname'] ) &&
  7. isset( $_POST['aboutme'] ) &&
  8. isset( $_POST['dateofbirth'] )
  9. )
  10. {
  11. if( strlen( $_POST['user'] ) < 4 )
  12. {
  13. echo "Username Must Be More Than 4 Characters.";
  14. }
  15. elseif( strlen( $_POST['pass'] ) < 4 )
  16. {
  17. echo "Passwrod Must Be More Than 4 Characters.";
  18. }
  19. elseif( $_POST['pass'] == $_POST['user'] )
  20. {
  21. echo"Username And Password Can Not Be The Same.";
  22. }
  23. else
  24. {
  25. include( 'database.php' );
  26.  
  27. $username = mysql_real_escape_string( $_POST['user'] );
  28. $password = md5( $_POST['pass'] );
  29. $firstname = mysql_real_escape_string( $_POST['firstname'] );
  30. $secondname = mysql_real_escape_string( $_POST['secondname'] );
  31. $aboutme = mysql_real_escape_string( $_POST['aboutme'] );
  32. $dateofbirth = mysql_real_escape_string( $_POST['dateofbirth'] );
  33.  
  34. $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";
  35.  
  36.  
  37. if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )
  38. {
  39. $sqlRegUser = "INSERT INTO
  40. user( username, password, firstname, secondname, aboutme, dateofbirth)
  41. VALUES(
  42. '". $username ."',
  43. '". $password ."'
  44. '". $firstname ."',
  45. '". $secondname ."',
  46. '". $aboutme ."',
  47. '". $dateofbirth ."',
  48. )";
  49.  
  50. if( !mysql_query( $sqlRegUser ) )
  51. {
  52. echo "You Could Not Register Because Of An Unexpected Error.";
  53. }
  54. else
  55. {
  56. echo "You Are Registered And Can Now Login";
  57. $formUsername = $username;
  58.  
  59. header ('location: Login.php');
  60. }
  61. }
  62. else
  63. {
  64. echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";
  65. $formUsername = $username;
  66. }
  67. }
  68. }
  69. else
  70. {
  71. echo "You Could Not Be Registered Because Of Missing Data.";
  72. }

no i potem jak prubuje sie zarejestrowac to wyskakuje "You Could Not Register Because Of An Unexpected Error.", jezeli ktos byl by na tyle mily zeby mi wytlumaczyc co zrobilem zle to byl bym bardzo wdzieczny. smile.gif prosze o wyrozumialosc, bo tak jak wczesniej pisalem jestem laikiem smile.gif
darko
no to:
1. zabrakło Ci `level` w insercie (regcheck.php)
2. linia 43 regcheck.php daj przecinek na końcu linii
grzybu
@darko
a gdzie dodoac ten level?? w ktorym miejscu i co napisac bo jak wczesniej pisalem jestem troche laikiem smile.gif
darko
Jeśli masz taką strukturę tabeli:

`id` int(4) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`firstaname` text collate latin1_general_ci NOT NULL,
`secondname` text collate latin1_general_ci NOT NULL,
`aboutme` text collate latin1_general_ci NOT NULL,
`level` int(4) NOT NULL DEFAULT '1',
`dateofbirth` date NOT NULL,

Może tak:

  1. $sqlRegUser = "INSERT INTO
  2. user( username, password, firstname, secondname, aboutme, level, dateofbirth)
  3. VALUES(
  4. '". $username ."',
  5. '". $password ."',
  6. '". $firstname ."',
  7. '". $secondname ."',
  8. '". $aboutme ."',
  9. '1',
  10. '". $dateofbirth ."'
  11. )";
grzybu
nie dalej nie dziala ;/
Kshyhoo
Logowanie to jedne z najtrudniejszych skryptów, laicy powinni zaczynać od "Hello world" ;P.
W bazie masz:
  1. `level` int(4) NOT NULL DEFAULT '1',

Powinieneś również odnieść się do niego w skrypcie, ominąłeś to, więc nie działa... Podaj chociaż link do tego tutoriala...

EDIT: ktoś był szybszy winksmiley.jpg
darko
upewnij się, że wszystkie zmienne które wstawiasz do zapytania mają odpowiednią wartość (np. wypisz je sobie echo $username itd.) oraz, że masz też dane w bazie smile.gif
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.