Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] You have an error in your SQL syntax
bartek4175
post 29.01.2014, 12:06:25
Post #1





Grupa: Zarejestrowani
Postów: 284
Pomógł: 1
Dołączył: 15.08.2013

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


Kod:
  1. <?php
  2. require_once("../zapytania.php");
  3. mysql_connect ("mysql3.superhost.pl","sh178151_admin","xxx"); //łącze z bazą ("serwer bazy","użytkownik","hasło")
  4. mysql_select_db ("sh178151_bartek4175"); //nazwa bazy
  5. mysql_query ("SET NAMES utf8"); //kodowanie znaków przydatne przy pobieraniu treści
  6.  
  7. function emotki($string) {
  8.  
  9. $emotikony = array(":D" => "http://firegifts.pl/images/emoticons/smilie5.gif",":)" => "http://firegifts.pl/images/emoticons/wink.gif", "lol2" => "http://emotikona.pl/emotikony/pic/01icon_lol2.gif", ":(" => "http://emotikona.pl/emotikony/pic/0sad.gif", ":P" => "http://emotikona.pl/emotikony/pic/0tongue.gif", "kurwa" => "http://firegifts.pl/images/emoticons/censored.gif", "huj" => "http://firegifts.pl/images/emoticons/censored.gif", "google" => "http://emotikona.pl/emotikony/pic/14icon_google.gif");
  10. foreach($emotikony as $tekst => $grafika) $string = str_replace($tekst,'<img src="'.$grafika.'" />',$string);
  11.  
  12. return $string;
  13. }
  14. $admin = mysql_query("SELECT * FROM users WHERE id = ".$data['id']."") or die;
  15.  
  16.  
  17. if(isset($_POST['wyslij']) && !empty($_POST['login']) && !empty($_POST['tresc']))
  18. {
  19. //Definicja zmiennych
  20. $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
  21. $tresc = mysql_real_escape_string(htmlspecialchars($_POST['tresc']));
  22. $data = date('Y-m-d H:i:s');
  23. $ip = $_SERVER['REMOTE_ADDR'];
  24.  
  25. //Wykonujemy zapytanie importujące zdefiniowane dane
  26. mysql_query ("INSERT INTO `posty` (`login`, `tresc`, `data`, `ip`) VALUES('$login', '$tresc', '$data', '$ip')");
  27.  
  28. //No i przenosimy użytkownika z powrotem do shoutboxa
  29. header('Location: '.$_SERVER['REQUEST_URI']);
  30. }
  31. else {
  32. //Pobieramy dane z bazy
  33. $query = mysql_query ("SELECT * FROM `posty` ORDER BY `data` DESC LIMIT 10");
  34. //Początek struktury tabeli
  35. echo '<table id="shoutbox">';
  36. //Pętla do wyświetlenia wszystkich wpisów
  37. while($shout=mysql_fetch_array($query)) {
  38. echo emotki('<tr class="wpis"><td>'
  39. .'<b> ');
  40.  
  41. echo emotki(''.$shout['login'].':</b></span> ' //wyświetlamy nick
  42. .$shout['tresc'] //wyświetlamy treść
  43. .'<br/><span class="data">'
  44. .$shout['data'] //wyświetlamy datę
  45. .'</span> ');
  46.  
  47. if (($data['admin']) == 1){
  48. if (isset($_GET['akcja']))
  49. {
  50. switch ($_GET['akcja'])
  51. {
  52. case 'spamer':
  53. mysql_query("DELETE FROM `posty` WHERE id = '" . (int)$_GET['id'] . "'") or die(mysql_error());
  54. break;
  55. }
  56. }
  57. ?><a href="/chat/index.php?akcja=usun&id=<? echo''.$shout['id'].''; ?> "> <span style="color:red;"><b>X</b></a></span><?
  58. }
  59. if (($data['admin']) == 1){
  60. if (isset($_GET['akcja']))
  61. {
  62. switch ($_GET['akcja'])
  63. {
  64. case 'spamer':
  65. mysql_query("INSERT INTO `users` (`spamer`) VALUES('1') WHERE '".$shout['login']."' = '".$data['login']."'") or die(mysql_error());
  66. break;
  67. }
  68. }
  69. ?><a href="/chat/index.php?akcja=spamer&login=<? echo''.$shout['login'].''; ?> "> <span style="color:green;"><b>S</b></a></span><?
  70. }
  71. echo emotki('</tr></td>');
  72. } //
  73.  
  74.  
  75. //Koniec struktury tabeli
  76. echo '</table>';
  77.  
  78. }
  79.  
  80.  
  81. //print_r($_SERVER);
  82. ?>
  83. <form action="" method="POST" id="shoutbox">
  84. <?php require_once("../zapytania.php"); echo'<input type="hidden" name="login" value="'.$data['login'].'" />'; ?><br/>
  85. Treść: <input type="text" name="tresc" maxlength="125" />
  86. <button type="submit" name="wyslij">Napisz</button>
  87. </form>

Błąd:
  1. 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 'Bartek4175' = 'Bartek4175'' at line 1
Go to the top of the page
+Quote Post

Posty w temacie


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: 14.08.2025 - 15:13