Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]problem z update w bazie
shtoc
post
Post #1





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

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


mam taki kod
  1. <?PHP
  2. $pdo = new PDO('mysql:host=localhost;dbname=wrzuta', 'admin', 'xxx');
  3. $pdo -> query ('SET NAMES utf8');
  4. $sql = "select * from filmy where key is null limit 1";
  5. $statement = $pdo->query($sql);
  6.  
  7. $row = $statement->fetch(PDO::FETCH_ASSOC);
  8. unset($statement);
  9.  
  10. $adres=$row['web'];
  11. #$adres ='http://daria24.wrzuta.pl/film/wdKctZmPkJ/';
  12.  
  13. $url = curl_init($adres);
  14. curl_setopt($url, CURLOPT_USERAGENT, 'holmes/3.10.1 (OnetSzukaj/5.0; +http://szukaj.onet.pl)');
  15. curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($url, CURLOPT_CONNECTTIMEOUT, 5);
  17. curl_setopt($url, CURLOPT_HEADER, 0);
  18. $strona=curl_exec($url);
  19. #curl_close($url);
  20.  
  21. $DOM = new DOMDocument();
  22. @$DOM->LoadHTML(iconv("ISO-8859-2","UTF-8",$strona));
  23. $tablica = array();  #deklaracja tablicy
  24.  
  25. foreach ($DOM->getElementsByTagName('input') as $input)
  26. {
  27.    $id = $input->getAttribute('id');
  28.    if($id == 'new_cmnt_key')
  29.    {
  30.        $key = $input->getAttribute('value');
  31.    }
  32.  
  33. }
  34.  
  35. foreach ($DOM->getElementsByTagName('input') as $input)
  36. {
  37.    $id = $input->getAttribute('id');
  38.    if($id == 'link_do_pliku')
  39.    {
  40.        $web = $input->getAttribute('value');
  41.        #$web = str_replace('"http://', 'www.', $webe->nodeValue);
  42.  
  43.    }
  44.  
  45. }
  46. #var_dump($web);
  47. #exit;
  48. foreach ($DOM->getElementsByTagName('input') as $input)
  49. {
  50.    $id = $input->getAttribute('id');
  51.    if($id == 'miniatura_embed')
  52.    {
  53.        $object = $input->getAttribute('value');
  54.    }
  55.  
  56. }
  57. foreach ($DOM->getElementsByTagName('title') as $title)
  58. {
  59.    $tytul = str_replace('Wrzuta.pl - ', '', $title->nodeValue);
  60. }
  61.  
  62.  
  63. foreach ($DOM->getElementsByTagName('meta') as $meta)
  64. {
  65.    $tag = $meta->getAttribute('name');
  66.    if($tag == 'keywords')
  67.    {
  68.        $tagi = $meta->getAttribute('content');
  69.    }
  70. }
  71.  
  72.  
  73.    $sql = "INSERT INTO filmy(`tytul`, `tag`, `url`, `web`, `created_at`) VALUES(:tytul, :tag, :url, :web, :created_at)";
  74.    $statement = $pdo->prepare($sql);
  75.    $statement->bindValue(':tytul', $tytul, PDO::PARAM_STR);
  76.    $statement->bindValue(':tag', $tagi, PDO::PARAM_STR);
  77.     $statement->bindValue(':url', $object, PDO::PARAM_STR);
  78.    $statement->bindValue(':web', $web, PDO::PARAM_STR);
  79.   # $statement->bindValue(':key', $key, PDO::PARAM_STR);
  80.    $statement->bindValue(':created_at', date( 'Y-m-d H:i:s', time()), PDO::PARAM_STR);
  81.    $statement->execute();
  82.    var_dump($statement->errorInfo());
  83.  
  84.  
  85. $sql = "update filmy set key = :key where id = :id";
  86. $statement = $pdo->prepare($sql);
  87. $statement->bindValue(':key', $key, PDO::PARAM_STR);
  88. $statement->bindValue(':id', $row['id'], PDO::PARAM_INT);
  89. $statement->execute();
  90. ?>



i do tego baze :
id INT unsigned notnull auto_increment
tytul text notnull
tag text notnull
url text notnull
web text notnull
key text null
created_at datatime notnull

do bazy mam wrzucone 3 rekordy w ktorych podane jest :
id tytul url web created_at

i idea kodu jest pobranie 1 filmiku z bazy ktory nie ma uzupelnionego key
pobranie jego adresu i z adresu pobranie jego key i wpisanie go do bazy.

ale nie dziala siedze nad tym caly dzien i lipa:/
dostaje blad

Fatal error: Call to a member function fetch() on a non-object in C:\Program Files\WebServ\httpd\pobieranie4.php on line 7

prosze pomozcie jak ktos wie gdzie jest blad??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
webmaniak
post
Post #2





Grupa: Zarejestrowani
Postów: 371
Pomógł: 30
Dołączył: 14.04.2010

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


Witam!
Mam taki kod:
  1. <a href="admin.php?page=zmien&id='.$row['id'].'">[Zmien]</a>

oczywiście także jest switch który odwołuje się do wybranej funkcji.
Funkcja wygląda tak:
  1. function zmien($id)
  2. {
  3. $y=mysql_query("SELECT opublikowane FROM articles");
  4.  
  5. if($wyn['opublikowane']==1)
  6. {
  7. $zmien = mysql_query("UPDATE `articles` SET opublikowane='0' WHERE id='$id'");
  8. }
  9. else
  10. {
  11. $zmien = mysql_query("UPDATE `articles` SET opublikowane='1' WHERE id='$id'");
  12. }
  13.  
  14.  
  15. if(mysql_query($zmien)) {
  16.  
  17. header( "refresh:2;url=admin.php" );
  18. }
  19. else echo 'blad';
  20. }

Kłopot z tym że nie zmienia mi wszystkiego i od razu. Mianowicie jest ciągle problem z pierwszym artykułem. Mianowicie jeśli pierwszy artykuł nie zmienię to drugi też nie idzie zmienić. Jednak jeśli zmienię ów pierwszy to drugi też da się zmienić. Natomiast pierwszy mogę zmieniać swobodnie. Będę wdzięczny za wszelką pomoc.

Znowu trochę próbowałem coś zmienić i nadal nie potrafię nic wymyśleć. Bardzo proszę o pomoc, bo rozwiązanie jest chyba blisko, ale nie potrafię znaleźć błędu.

Ten post edytował webmaniak 25.05.2010, 17:24:12
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: 8.10.2025 - 14:50