Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z poleceniem wysyłanym do bazy
Forum PHP.pl > Forum > PHP
furman12
Witam mam plik i chce, żeby wysyłał z formularza wartość z tabeli country z pola id zawartość do tabeli player i pola country, w zasadzie wysyła, ale bezsensowny ciąg zamiast id. Co tu jest źle? Pomoże ktoś
  1. <?php
  2. include("lib.php");
  3. define("PAGENAME", "Twoje konto");
  4. $player = check_user($secret_key, $db);
  5.  
  6. $query = $db->execute("update `players` set `country`=? where `id`=?", array(sha1($_POST['country']), $player->id));
  7. ?>
  8. <form method="POST" action="country.php">
  9. <tr><td width="40%"><B>Wybierz swoją narodowość:</B>
  10. <select name="country">
  11. <? $query = $db->execute("select `id`, `country` from `country`");
  12. while($country = $query->fetchrow()){;?>
  13. <option value="<?=$country['id']?><?=$country['country']?></option>
  14.  
  15. <?
  16.  
  17. }
  18.  
  19. ?>
  20. </select><br /></td></tr>
  21.  
  22. <tr><td colspan="2" align="center"><input type="submit" name="register" value="Zmień!"></td></tr>
  23. </table>
  24. </form>


dodam, że cała konfiguracja jest w pliku lib.php
darko
1. linia numer 12 usuń ten średnik
2. linia 13 zobacz jak nie wygląda Twoje option: otwierasz tag option i cudzysłów dla wartości atrybutu value i ani nie zamykasz cudzysłowu, ani taga option, czyli:
<option value="Cos_tam1Cos_tam2</option>

i jak to ma działać ?
furman12
Poprawiłem tak jak mówiłeś, ale nadal wysyła do bazy jakieś dziadostwo. Wpisało 356a192b7913b04c54574d18c28d46e6395428ab a powinno 1.
darko
Daj cały kod, skąd mam wiedzieć? W linii 6 nie powinien być select (chcesz chyba pobrać i wyświetlić dane, a nie robić update, tak ? )
furman12
  1. <?php
  2. include("lib.php");
  3. define("PAGENAME", "Wbór narodowości");
  4. $player = check_user($secret_key, $db);
  5.  
  6. $query = $db->execute("update `players` set `country`=? where `id`=?", array(sha1($_POST['country']), $player->id));
  7. ?>
  8. <form method="POST" action="country.php">
  9. <tr><td width="40%"><B>Wybierz swoją narodowość:</B>
  10. <select name="country">
  11. <? $query = $db->execute("select `id`, `country` from `country`");
  12. while($country = $query->fetchrow()){?>
  13. <option value="<?=$country['id']?>"><?=$country['country']?></option>
  14.  
  15. <?
  16.  
  17. }
  18.  
  19. ?>
  20. </select><br /></td></tr>

  21. <tr><td colspan="2" align="center"><input type="submit" name="register" value="Zmień!"></td></tr>
  22. </table>
  23. </form>


Chce, żeby z formularza wpisalo id do pola country. Wcześniej była zła nazwa i to cie mogło zmylić.

Zmodyfikowałem to tak:
  1. <?php
  2. include("lib.php");
  3. define("PAGENAME", "Wybór narodowości");
  4. $player = check_user($secret_key, $db);
  5. $query = $db->execute("INSERT INTO `players` SET `country`=? where `id`=?>", array(sha1($country['id']), $player->id)) or die(mysql_error());
  6. ?>
  7. <form method="POST" action="country.php">
  8. <tr><td width="40%"><B>Wybierz swoją narodowość:</B>
  9. <select name="country">
  10. <? $query = $db->execute("select `id`, `country` from `country`");
  11. while($country = $query->fetchrow()){?>
  12. <option value="<?=$country['id']?>"><?=$country['country']?></option>
  13.  
  14. <?
  15.  
  16. }
  17.  
  18. ?>
  19. </select><br /></td></tr>

  20. <tr><td colspan="2" align="center"><input type="submit" name="register" value="Zmień!"></td></tr>
  21. </table>
  22. </form>

I nic mysql zwraca taki komunikat
Kod
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 'where `id`='9'>' at line 1

Dodam, że ta 9 to moje id
darko
linia 5 usuń znak >
furman12
Poprawka naniesiona ale dalej ten sam komunikat tylko bez >
darko
Wyprintuj całe zapytanie i pokaż je tutaj oraz podaj strukturę tabeli
furman12
plik:
  1. <?php
  2. include("lib.php");
  3. define("PAGENAME", "Twoje konto");
  4. $player = check_user($secret_key, $db);
  5. $query = $db->execute("INSERT INTO `players` SET `country`=? where `id`=?", array(sha1($country['id']), $player
  6.  
  7. ->id)) or die(mysql_error());
  8. ?>
  9. <form method="POST" action="country.php">
  10. <tr><td width="40%"><B>Wybierz swoją narodowość:</B>
  11. <select name="country">
  12. <? $query = $db->execute("select `id`, `country` from `country`");
  13. while($country = $query->fetchrow()){?>
  14. <option value="<?=$country['id']?>"><?=$country['country']?></option>
  15.  
  16. <?
  17.  
  18. }
  19.  
  20. ?>
  21. </select><br /></td></tr>

  22. <tr><td colspan="2" align="center"><input type="submit" name="register" value="Zmień!"></td></tr>
  23. </table>
  24. </form>


komunikat:
Kod
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 'where `id`='9'' at line 1


players:
  1. -- Struktura tabeli dla `players`
  2. --
  3.  
  4. CREATE TABLE IF NOT EXISTS `players` (
  5. `id` int(11) NOT NULL AUTO_INCREMENT,
  6. `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  7. `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  8. `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  9. `rank` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Użytkownik',
  10. `registered` int(11) NOT NULL,
  11. `last_active` int(11) NOT NULL,
  12. `ip` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  13. `level` int(11) NOT NULL DEFAULT '1',
  14. `stat_points` int(11) NOT NULL DEFAULT '5',
  15. `gold` int(11) NOT NULL DEFAULT '10',
  16. `bank` int(11) NOT NULL DEFAULT '0',
  17. `hp` int(11) NOT NULL DEFAULT '50',
  18. `maxhp` int(11) NOT NULL DEFAULT '50',
  19. `exp` int(11) NOT NULL DEFAULT '0',
  20. `maxexp` int(11) NOT NULL DEFAULT '50',
  21. `energy` int(11) NOT NULL DEFAULT '10',
  22. `maxenergy` int(11) NOT NULL DEFAULT '10',
  23. `strength` int(11) NOT NULL DEFAULT '1',
  24. `vitality` int(11) NOT NULL DEFAULT '1',
  25. `agility` int(11) NOT NULL DEFAULT '1',
  26. `interest` tinyint(1) NOT NULL DEFAULT '0',
  27. `kills` int(11) NOT NULL DEFAULT '0',
  28. `deaths` int(11) NOT NULL DEFAULT '0',
  29. `race` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  30. `validated` int(11) NOT NULL DEFAULT '0',
  31. `validkey` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
  32. `guild_id` int(11) DEFAULT NULL,
  33. `country` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  34. PRIMARY KEY (`id`)
  35. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=30 ;


country:
  1. -- Struktura tabeli dla `country`
  2. --
  3.  
  4. CREATE TABLE IF NOT EXISTS `country` (
  5. `id` int(11) NOT NULL AUTO_INCREMENT,
  6. `country` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  7. PRIMARY KEY (`id`)
  8. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;


W formie z 1 postu był dodawany bezwładny ciąg znaków, choć powinna być dodawana 1, więc jako tako działa, ale nie wiem co jest źle.

Problem rozwiązany przyczyną była funkcja sha1, zawdzięczam swoje problemy swojemu lenistwu, gdyż wyciołem skrawek kodu z innego mojego pliku, a to, że w php nie jestem za mocny przyczyniło się do nie odnalezienia problemu w czasie. Tu jest dobry plik.
  1. <?php
  2. include("lib.php");
  3. define("PAGENAME", "Wybór narodowości");
  4. $player = check_user($secret_key, $db);
  5.  
  6. $query = $db->execute("update `players` set `country`=? where `id`=?", array($_POST['country'], $player->id)) or die(mysql_error());
  7. ?>
  8. <form method="POST" action="country.php">
  9. <tr><td width="40%"><B>Wybierz swoją narodowość:</B>
  10. <select name="country">
  11. <? $query = $db->execute("select `id`, `country` from `country`");
  12. while($country = $query->fetchrow()){?>
  13. <option value="<?=$country['id']?>"><?=$country['country']?></option>
  14.  
  15. <?
  16.  
  17. }
  18.  
  19. ?>
  20. </select><br /></td></tr>

  21. <tr><td colspan="2" align="center"><input type="submit" name="register" value="Zmień!"></td></tr>
  22. </table>
  23. </form>
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.