Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] problem z zapytaniem
jjarkus
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 26.08.2008

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


Dręczy mnie pewien problem z moim kodem (IMG:style_emoticons/default/blinksmiley.gif)
Mianowicie tworzę sobie taką małą grę i problem jest następujący:
Podczas rejestracji nowego użytkownika wyskakuje taki błąd:
Kod
         Warning:  mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\usr\krasnal\www\gra\stats.php on line 43
         Warning:  mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\usr\krasnal\www\gra\stats.php on line 43
         Warning:  mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\usr\krasnal\www\gra\stats.php on line 43

Skorzystałem też z
i pokazał taki komunikat:
Kod
         Something is wrong in your syntax obok 'SELECT id FROM stats WHERE display_name = 'mag' OR short_name = ' w linii 1


Wychodzi na to, że chyba wykonanie zapytania się nie powiodło.
W czym może tkwić błąd?

Dodatkowo kod stats.php
  1. <?php
  2.  
  3. function getStat($statName,$userID) {
  4. include 'config.php';
  5. $conn = mysql_connect($dbhost,$dbuser,$dbpass)
  6. or die ('Error connecting to mysql:');
  7. mysql_select_db($dbname);
  8. createIfNotExists($statName,$userID);
  9. $query = sprintf("SELECT value FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",
  10. $result = mysql_query($query);
  11. list($value) = mysql_fetch_row($result);
  12. return $value;
  13. $userID = mysql_insert_id($conn);
  14.  
  15. }
  16. function setStat($statName,$userID,$value) {
  17. include 'config.php';
  18. $conn = mysql_connect($dbhost,$dbuser,$dbpass)
  19. or die ('Error connecting to mysql');
  20. mysql_select_db($dbname);
  21. createIfNotExists($statName,$userID);
  22. $query = sprintf("UPDATE user_stats SET value = '%s' WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",
  23. $result = mysql_query($query);
  24. }
  25.  
  26. function createIfNotExists($statName,$userID) {
  27. include 'config.php';
  28. $conn = mysql_connect($dbhost,$dbuser,$dbpass)
  29. or die ('Error connecting to mysql:');
  30. mysql_select_db($dbname);
  31. $query = sprintf("SELECT count(value) FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s') AND user_id = '%s'",
  32. $result = mysql_query($query);
  33. list($count) = mysql_fetch_row($result);
  34. if($count == 0) {
  35. $query = sprintf("INSERT INTO user_stats(stat_id,user_id,value) VALUES ((SELECT id FROM stats WHERE display_name = '%s' OR short_name = '%s'),'%s','%s')",
  36. '0');
  37. mysql_query($query);
  38. }
  39. }
  40.  
  41. ?>


Oraz register.php
  1. <?php
  2.  
  3. include 'smarty.php';
  4.  
  5. if($_POST) {
  6. $password = $_POST['password'];
  7. $confirm = $_POST['confirm'];
  8. if($password != $confirm) {
  9. $error = 'Passwords do not match!';
  10. } else {
  11. require_once 'config.php';
  12. $conn = mysql_connect($dbhost,$dbuser,$dbpass)
  13. or die('Error connecting to mysql');
  14. mysql_select_db($dbname);
  15. $query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')",
  16. mysql_real_escape_string($_POST['username']));
  17. $result = mysql_query($query);
  18. list($count) = mysql_fetch_row($result);
  19. if($count >= 1) {
  20. $error = 'that username is taken.';
  21. } else {
  22. $query = sprintf("INSERT INTO users(username,password) VALUES ('%s','%s');",
  23. mysql_real_escape_string($_POST['username']),
  24. mysql_query($query);
  25. $userID = mysql_insert_id($conn);
  26. require_once 'stats.php';
  27. setStat('atk',$userID,'5');
  28. setStat('def',$userID,'5');
  29. setStat('mag',$userID,'5');
  30. $message = 'Congratulations, you registered successfully!';
  31. }
  32. }
  33. }
  34. $smarty->assign('error',$error);
  35. $smarty->assign('message',$message);
  36. $smarty->display('register.tpl');
  37. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 23.08.2025 - 04:33