Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php][mysql]nie moge dodać danych do bazy
marcin86s
post 29.11.2007, 16:05:59
Post #1





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 29.11.2007
Skąd: City 17

Ostrzeżenie: (0%)
-----


  1. <?php
  2. require(&#092;"admin/config.php\");
  3. mysql_connect($dbhost, $dbuser, $dbpass) or system_error('ERROR: Can not connect to MySQL-Server');
  4. mysql_select_db($dbname) or system_error('ERROR: Can not connect to database \"'.$dbname.'\"');
  5.  
  6. if (empty($_POST['submit']))
  7. {
  8. echo &#092;"
  9.  
  10. Login: 
  11.  
  12. Hasło: 
  13.  
  14. Hasło powtórz: 
  15.  
  16. Mail: 
  17.  
  18. Gadu-Gadu: 
  19.  
  20.  
  21.  
  22. &#092;";
  23. }
  24. else
  25. {
  26. $nick = mysql_real_escape_string($_POST['nick']);
  27. if($_POST['pass1'] == $_POST['pass2'])
  28. {
  29. $pw = $_POST['pass1'];
  30. $password = md5(sha1($pw));
  31. }
  32. $mail = mysql_real_escape_string($_POST['mail']);
  33. $gg = mysql_real_escape_string($_POST['gg']);
  34. $query = &#092;"INSERT INTO aa_users ('nick', 'password', 'rights', 'mail', 'gg') VALUES ('$nick', '$password', 'user', '$mail', '$gg')\";
  35. $result = mysql_query($query);
  36. if(!$result)
  37. }
  38. ?>


I wywala mi coś takiego:

Cytat
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''nick', 'password', 'rights', 'mail', 'gg') VALUES ('login', '43e21d857296a7f997' at line 1


Ten post edytował marcin86s 29.11.2007, 21:07:18
Go to the top of the page
+Quote Post
PawelC
post 29.11.2007, 16:10:27
Post #2





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

Ostrzeżenie: (0%)
-----


  1. <?php
  2. require("admin/config.php");
  3. mysql_connect($dbhost, $dbuser, $dbpass) or system_error('ERROR: Can not connect to MySQL-Server');
  4. mysql_select_db($dbname) or system_error('ERROR: Can not connect to database "'.$dbname.'"');
  5.  
  6. if (empty($_POST['submit']))
  7. {
  8. echo "
  9. <form method=\"post\" action=\"register.php\">
  10. Login: <input type=\"text\" name=\"nick\"><br>
  11. Hasło: <input type=\"password\" name=\"pass1\"><br>
  12. Hasło powtórz: <input type=\"password\" name=\"pass2\"><br>
  13. Mail: <input type=\"text\" name=\"mail\"><br>
  14. Gadu-Gadu: <input type=\"text\" name=\"gg\"><br>
  15. <input type=\"submit\" name=\"submit\" value=\"Wyslij\">
  16. </form>
  17. ";
  18. }
  19. else
  20. {
  21. $nick = mysql_real_escape_string($_POST['nick']);
  22. if($_POST['pass1'] == $_POST['pass2'])
  23. {
  24. $pw = $_POST['pass1'];
  25. $password = md5(sha1($pw));
  26. }
  27. $mail = mysql_real_escape_string($_POST['mail']);
  28. $gg = mysql_real_escape_string($_POST['gg']);
  29.  $query="INSERT INTO aa_users (`id`,`nick`, `password`, `rights`, `mail`, `gg`) VALUES ('null','$nick', '$password', '$user', '$mail', '$gg')";
  30. $result = mysql_query($query);
  31. if(!$result)
  32. }
  33. ?>

Zobacz tak. A tutaj miałeś brak znaku dolara
  1. <?php
  2. VALUES ('$nick', '$password', 'user', '$mail', '$gg')";
  3. ?>
Go to the top of the page
+Quote Post
marcin86s
post 29.11.2007, 20:28:54
Post #3





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 29.11.2007
Skąd: City 17

Ostrzeżenie: (0%)
-----


Wygląda na to że mój błąd polegał na tym ze dawałem ' zamiast ` ohmy.gif Mam taki problem, jak to napisać żeby działało? Teraz co bym nie wpisał to zalogowało. blink.gif

  1. <?php
  2. require("admin/config.php");
  3. mysql_connect($dbhost, $dbuser, $dbpass) or system_error('ERROR: Can not connect to MySQL-Server');
  4. mysql_select_db($dbname) or system_error('ERROR: Can not connect to database "'.$dbname.'"');
  5.  
  6.  
  7. if(empty($_POST['submit']))
  8. {
  9. echo "
  10. <form method=\"post\" action=\"login.php\">
  11. Login: <input type=\"text\" name=\"login\"><br>
  12. Hasło: <input type=\"password\" name=\"pass\"><br>
  13. <input type=\"submit\" name=\"submit\" value=\"Wyslij\">
  14. </form>
  15. ";
  16. }
  17. else
  18. {
  19. $login = mysql_real_escape_string($_POST['login']);
  20. $pass = md5(sha1($_POST['pass']));
  21. $query = "SELECT nick, password FROM ".PREFIX."users WHERE nick='$login' AND password='$pass'";
  22. $result = mysql_query($query);
  23. if(empty($result))
  24. {
  25. echo "Błędne hasło";
  26. }
  27. else
  28. {
  29. echo "Niby zalogowano";
  30. }
  31. if(!$result)
  32. }
  33. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 12.07.2025 - 20:36