Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Skrypt Newsów
Sign
post 5.11.2014, 21:11:27
Post #1





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Zrobiłem już panel tutaj
http://signweb.xaa.pl/system/panel/add_post.php
I chciałbym, aby po wypełnieniu tego Tytuł i Treśc wszystko pokazywalo się na stronie głownej czyli tutaj
http://signweb.xaa.pl/system/
Tytuł w tym boxie na gornej belce, a text w tym boxie na tym bialym tle.
od czego zaczac ?
Nakierowalby mnie ktos tzn. zapoczątkowal kod itp ? Ja bym o wlasnych silach dokonczyl.
pozdrwawiam
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
Boshi
post 5.11.2014, 21:42:41
Post #2





Grupa: Zarejestrowani
Postów: 342
Pomógł: 15
Dołączył: 30.08.2011

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


Nie zakładaj nowych tematów co chwilę, przecież ci napisałem w innym co masz zrobić.

W index.html

1 Wysyłasz zapytanie do bazy
2 pobierasz wyniki w formie np tablicy
3 za pomocą pętli while wyświetlasz wyniki w odpowiednim kodzie css. Tytuł-tytuł, treść-box treść

Go to the top of the page
+Quote Post
Sign
post 5.11.2014, 23:32:33
Post #3





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Mozna troszkę jasniej ?
PS TO musi byc index.html cyz moze byc index.php ;3

Jak już jako tako sobie radze to wyskoczył mi błąd wink.gif
Po kliknieciu wyslij pod formularzem pokazuje sie
  1. Warning: mysql_query() [function.mysql-query]: Access denied for user 'signweb'@'localhost' (using password: NO) in /home/signweb/public_html/system/panel/add_post.php on line 30
  2.  
  3. Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/signweb/public_html/system/panel/add_post.php on line 30


To jest add_post.php
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <head>
  4. <title> Dodaj Post</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="../style/panel.css" />
  7. </head>
  8. <body>
  9.  
  10. <div id="header"></div>
  11. <div id="menu">
  12. <div class="szerokosc">
  13. <a href="#" class="menu">Ustawienia</a>
  14. <a href="add_post.php" class="menu">Dodaj News !</a>
  15. <a href="#" class="menu">Aktualnie Brak</a>
  16. <a href="#" class="menu">Aktualnie Brak</a>
  17. </div>
  18. </div>
  19.  
  20. <div id="box">
  21.  
  22.  
  23. <form action="" method="post">
  24. tytuł: <input type="text" name="tytul">
  25. <br/>autor <input type="text" name="autor">
  26. <br/>treść <textarea name="tresc" rows="20" cols="50"></textarea>
  27. <br/><input type="submit" value="Dodaj"></form>
  28. <?php
  29. include("config.php");
  30. $query = mysql_query("insert into news values('','".$_POST['tytul']."',now(),'".$_POST['autor']."','".$_POST['tresc']."')");
  31. ?>
  32.  
  33. </div>
  34.  
  35.  
  36. </body>
  37. </html>


a w tym boxie w którym ma sie to pojawic to pokazuje sie
  1. Warning: mysql_query() [function.mysql-query]: Access denied for user 'signweb'@'localhost' (using password: NO) in /home/signweb/public_html/system/index.php on line 24
  2.  
  3. Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/signweb/public_html/system/index.php on line 24
  4.  
  5. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/signweb/public_html/system/index.php on line 25


a to kod index.php
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <head>
  4. <title> Dodaj Newsa </title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="style/glowna.css" />
  7. </head>
  8. <body>
  9.  
  10. <div id="header"></div>
  11. <div id="menu">
  12. <div class="szerokosc">
  13. <a href="#" class="menu">Ustawienia</a>
  14. <a href="add_post.php" class="menu">Dodaj News !</a>
  15. <a href="#" class="menu">Aktualnie Brak</a>
  16. <a href="#" class="menu">Aktualnie Brak</a>
  17. </div>
  18. </div>
  19.  
  20. <div id="box">
  21.  
  22. <?php
  23. include("panel/config.php");
  24. $query = mysql_query("select * from news order by id desc limit 0,5");
  25. while($rekord = mysql_fetch_array($query))
  26. {
  27. $naz .= ''.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'</li>';
  28. }
  29. echo '<ul>'.$naz.'</ul>';
  30. ?>
  31.  
  32. </div>
  33.  
  34.  
  35. </body>
  36. </html>



Mam nadzieje, że ktos mi pomoże to naprawic i wyjasni co jest tego winą.

Pozdrawiam
Go to the top of the page
+Quote Post
Boshi
post 6.11.2014, 01:40:53
Post #4





Grupa: Zarejestrowani
Postów: 342
Pomógł: 15
Dołączył: 30.08.2011

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


Ma być index.php

A czytać chyba potrafisz...

  1. Access denied for user 'signweb'@'localhost' (using password: NO)...

oznacza, brak połączenia z bazą. Prawdopodobnie błędne dane podałeś.

  1. now()

Co to za wytwór wyobraźni?

  1. $query = mysql_query("insert into news values('','".$_POST['tytul']."',now(),'".$_POST['autor']."','".$_POST['tresc']."')");

Dane nie są w żaden sposób filtrowane przed wstawieniem do bazy.


  1. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/signweb/public_html/system/index.php on line 25

Oznacza błąd w zapytaniu SQL.

Zacznij od podstaw.


Go to the top of the page
+Quote Post
in5ane
post 6.11.2014, 11:27:08
Post #5





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

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


Rada ode mnie. W dzisiejszych czasach warto nakłaniać użytkowników do porzucenia funkcji z rodziny mysql_. Mamy PHP 5.5, w którym funkcje z rodziny mysql_ opisane są jako przestarzałe i zalecamy używać bliźniaczo podobnych funkcji z rodziny mysqli_ lub PDO.

Ten post edytował in5ane 6.11.2014, 11:27:53


--------------------
> > > Tworzenie stron < < <
Go to the top of the page
+Quote Post
Sign
post 6.11.2014, 17:43:18
Post #6





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Czyli to
  1. $query = mysql_query("insert into news values('','".$_POST['tytul']."',now(),'".$_POST['autor']."','".$_POST['tresc']."')");

Na co zmeinic questionmark.gif
Go to the top of the page
+Quote Post
viking
post 6.11.2014, 18:02:44
Post #7





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


W wersji dłuższej:
  1. try {
  2. $dbh = new PDO($dsn, $user, $pass);
  3. $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  4. $dbh->exec("SET NAMES 'UTF8';");
  5. $sql = "INSERT INTO news VALUES(:tytul, NOW(), :autor, :tresc)";
  6. $sth = $dbh->prepare($sql);
  7. $sth->bindParam(':tytul', $_POST['tytul'], PDO::PARAM_STR);
  8. $sth->bindParam(':autor', $_POST['autor'], PDO::PARAM_STR);
  9. $sth->bindParam(':tresc', $_POST['tresc'], PDO::PARAM_INT, 3);
  10. $sth->execute();
  11. } catch(PDOException $e) {
  12. echo 'Klasa PDO zwróciła wyjątek: '.$e->getMessage();
  13. }


Źródło: http://wwwgo.pl/article/10/php_data_object...luge_baz_danych


--------------------
Go to the top of the page
+Quote Post
Sign
post 6.11.2014, 18:52:14
Post #8





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Zeby nie robic nowego tematu to odrazu zapytam tutaj.
Jak mam Upload Plikow i wrzucam np 2 razy plik reklama.png to co zrobic, aby po drugim razie nie podmienialo tego pierwszego pliku tylko tego drugiego pliku byla taka nazwa np.
reklama_768126317238.png
Da rade tak ?
Tak wyglada kawel kodu ktory odpowiada za nazwe biggrin.gif
  1. move_uploaded_file($plik_tmp, "upload/$plik_nazwa" );
Go to the top of the page
+Quote Post
nospor
post 6.11.2014, 18:53:52
Post #9





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




No, najpierw sprawdzasz, czy plik o podanej nazwie już istnieje i jesli tak, to albo zmieniasz staremu nazwe na inną albo nowemu na inną. Do sprawdzenia czy istnieje uzywa sie file_exists()


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Sign
post 6.11.2014, 18:57:46
Post #10





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


a aby nadaawlo tą nową nazwe to jakiego kodu uzyc trzeba biggrin.gif?
Go to the top of the page
+Quote Post
nospor
post 6.11.2014, 18:58:23
Post #11





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




staremu nową nazwe? rename()


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Sign
post 8.11.2014, 13:31:01
Post #12





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


To jak nie flitruje przed dodaniem do bazy
  1. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/signweb/public_html/system/index.php on line 25


To na co podmienic ten kod ?
  1. while($rekord = mysql_fetch_array($query))


PS co moze byc przyczyną tego błędu

Warning: mysql_query() [function.mysql-query]: Access denied for user 'signweb'@'localhost' (using password: NO) in /home/signweb/public_html/system/index.php on line 24 jak na 100% jest dobre dane podalem ?
Go to the top of the page
+Quote Post
Turson
post 8.11.2014, 13:46:45
Post #13





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Cytat
To jak nie flitruje przed dodaniem do bazy

To filtruj. Dane które wstawiasz pewnie zawierają niedozwolone znaki i wykrzaczają zapytanie. Sprawdzaj jak zapytanie wygląda.

Cytat
To na co podmienic ten kod ?

Tzn...?

Cytat
PS co moze byc przyczyną tego błędu

Warning: mysql_query() [function.mysql-query]: Access denied for user 'signweb'@'localhost' (using password: NO) in /home/signweb/public_html/system/index.php on line 24 jak na 100% jest dobre dane podalem ?

Twój user nie ma uprawnien
Go to the top of the page
+Quote Post
Sign
post 8.11.2014, 13:52:23
Post #14





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Dodalem mu wszystkie przywileje jesli o to chodzi biggrin.gif
Go to the top of the page
+Quote Post
viking
post 8.11.2014, 14:33:08
Post #15





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Skoro miałeś korzystać z PDO to dlaczego dalej klepiesz mysql_? Użytkownik wyraźnie nie ma uprawnień. Być może zamiast localhost pomoże 127.0.0.1


--------------------
Go to the top of the page
+Quote Post
Sign
post 8.11.2014, 17:26:44
Post #16





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


to ten kod mam podmienic na ten z PDO ?
Go to the top of the page
+Quote Post
Boshi
post 8.11.2014, 18:42:56
Post #17





Grupa: Zarejestrowani
Postów: 342
Pomógł: 15
Dołączył: 30.08.2011

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


Tak.
Go to the top of the page
+Quote Post
Sign
post 8.11.2014, 19:33:43
Post #18





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


Podmienilem i mam takie cos.

Warning: mysql_query() [function.mysql-query]: Access denied for user 'signweb'@'localhost' (using password: NO) in /home/signweb/public_html/system/index.php on line 24

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/signweb/public_html/system/index.php on line 24
Klasa PDO zwróciła wyjątek: invalid data source name

"> Autor: -


Co zrobic, aby user mial te prawa ?
Go to the top of the page
+Quote Post
Boshi
post 8.11.2014, 19:41:57
Post #19





Grupa: Zarejestrowani
Postów: 342
Pomógł: 15
Dołączył: 30.08.2011

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


Pokaż cały ten kod..
Go to the top of the page
+Quote Post
Sign
post 8.11.2014, 19:47:36
Post #20





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 3.11.2014

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


index.php
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <head>
  4. <title> Dodaj Newsa </title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="style/glowna.css" />
  7. </head>
  8. <body>
  9.  
  10. <div id="header"></div>
  11. <div id="menu">
  12. <div class="szerokosc">
  13. <a href="#" class="menu">Ustawienia</a>
  14. <a href="add_post.php" class="menu">Dodaj News !</a>
  15. <a href="#" class="menu">Aktualnie Brak</a>
  16. <a href="#" class="menu">Aktualnie Brak</a>
  17. </div>
  18. </div>
  19.  
  20. <div id="box">
  21.  
  22. <?php
  23. include("panel/polacz.php");
  24. $query = mysql_query("select * from news order by id desc limit 0,5");
  25. try {
  26. $dbh = new PDO($dsn, $user, $pass);
  27. $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  28. $dbh->exec("SET NAMES 'UTF8';");
  29. $sql = "INSERT INTO news VALUES(:tytul, NOW(), :autor, :tresc)";
  30. $sth = $dbh->prepare($sql);
  31. $sth->bindParam(':tytul', $_POST['tytul'], PDO::PARAM_STR);
  32. $sth->bindParam(':autor', $_POST['autor'], PDO::PARAM_STR);
  33. $sth->bindParam(':tresc', $_POST['tresc'], PDO::PARAM_INT, 3);
  34. $sth->execute();
  35. } catch(PDOException $e) {
  36. echo 'Klasa PDO zwróciła wyjątek: '.$e->getMessage();
  37. }{
  38. $naz .= ''.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'</li>';
  39. }
  40. echo '<ul>'.$naz.'</ul>';
  41. ?>
  42.  
  43. </div>
  44.  
  45.  
  46. </body>
  47. </html>
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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 - 06:31