Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MYSQL] problem z zapytaniem
shtoc
post
Post #1





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 18.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


napisalem skrypt

  1. <?php
  2. mysql_connect('111.111.111.111', 'admin', 'xxx') or die('Błąd połączenia: '.mysql_error());
  3. mysql_selectdb('baza') or die('Błąd wyboru bazy: '.mysql_error());
  4.  
  5. $sql = "select * from test3 where tytul is not null limit 10";
  6. $res = mysql_query($sql);
  7.  
  8. while($row = mysql_fetch_array($res))
  9. {
  10.  
  11.   //echo $row['tytul'].$row['url'];
  12.   mysql_connect('localhost', 'aaa', 'xxxx') or die('Błąd połączenia: '.mysql_error());
  13.   mysql_selectdb('maszyny') or die('Błąd wyboru bazy: '.mysql_error());
  14.   $sql= "INSERT INTO wp_posts(`post_title`,`post_content`) VALUES($row['tytul'],$row['url'])";
  15.   $aaa= mysql_query($sql);
  16.   echo mysql_errno($aaa) . ": " . mysql_error($aaa);
  17.  
  18. }
  19.  
  20. ?>


mam problem z 2 zapytaniem sql caly czas mam bład

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/konta/.../baza.php on line 15

probowalem na rozne sposoby ze zmiennym i nic
moze ktos wie jak to powinno byc zrobione (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (PDO nie dzial na serwie wiec nie wchodzi w gre)

jak zamiast
VALUES($row['tytul'],$row['url'])";
dam
Values('costam','costam2')";

to normalnie dodaje do bazy!!

Ten post edytował shtoc 5.01.2009, 13:12:23
Go to the top of the page
+Quote Post
Lion_87
post
Post #2





Grupa: Zarejestrowani
Postów: 850
Pomógł: 120
Dołączył: 15.02.2007
Skąd: Łódź

Ostrzeżenie: (10%)
X----


a może tak daj......
  1. <?php
  2.  $sql= "INSERT INTO wp_posts(`post_title`,`post_content`)  VALUES(".$row['tytul'].",".$row['url'].")
  3. ?>


Ten post edytował Lion_87 5.01.2009, 13:06:29
Go to the top of the page
+Quote Post
shtoc
post
Post #3





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 18.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


niby błędu w netbeans juz nie ma w skladni zapytania ale jest po wywolaniu skryptu :

Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/konta/../baza.php on line 17

Ten post edytował shtoc 5.01.2009, 13:12:03
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




nie: mysql_errno($aaa)
a: mysql_errno()
Go to the top of the page
+Quote Post
shtoc
post
Post #5





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 18.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 5.01.2009, 13:17:04 ) *
nie: mysql_errno($aaa)
a: mysql_errno()


to wynik błedu 1064: 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 ':Telewizor na miar? XXI wieku.,:
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




no ale tekst trzeba brac w apostrofy:
  1. <?php
  2. $sql= "INSERT INTO wp_posts(`post_title`,`post_content`)  VALUES('".$row['tytul']."','".$row['url']."')";
  3. ?>
Go to the top of the page
+Quote Post
melkorm
post
Post #7





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


hehe manual
Cytat
int mysql_errno ([ resource $identyfikator_połączenia ] )


więc nie zapytanie tylko połączenie :] Czyli zamiast :
  1. <?php
  2. echo mysql_errno($aaa) . ": " . mysql_error($aaa);
  3. ?>


daj :

  1. <?php
  2. echo mysql_errno() . ": " . mysql_error(); // lub zapisz do zmiennej id połączenia
  3. ?>



edit:
za wolny jestem z tymi odpowiedziami :|

Ten post edytował melkorm 5.01.2009, 13:23:09
Go to the top of the page
+Quote Post
Lion_87
post
Post #8





Grupa: Zarejestrowani
Postów: 850
Pomógł: 120
Dołączył: 15.02.2007
Skąd: Łódź

Ostrzeżenie: (10%)
X----


BO moze tak
  1. <?php
  2. $sql= "INSERT INTO wp_posts(`post_title`,`post_content`)  VALUES('".$row['tytul']."','".$row['url']."')";
  3. ?>
Go to the top of the page
+Quote Post
shtoc
post
Post #9





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 18.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


a jednak zapytanie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

nospor mial racje (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif)

dziekuje!!

napotkałem na jeszcze jeden problem z zapytaniem
a mianowicie
  1. <?php
  2. $sql = "select * from test3 where tytul is not null limit 7000";
  3. ?>

pobieram z jednej bazy filmiki z limitem 7000 wszystko ladnie zapisuje sie do 2 bazy ale w wyniku dostaje 6 761 rekordówi i bład :

0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 1064: 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 't Cry - Buffo Amerykański','

co jest nie tak (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Ten post edytował shtoc 5.01.2009, 17:45:38
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




niech zgadne: cale slowo to: don't cry (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Musisz escapowac dane zanim je wlozysz do zapytania
http://pl2.php.net/manual/pl/function.mysq...cape-string.php
Go to the top of the page
+Quote Post

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: 5.10.2025 - 04:07