Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]echo z date w zmiennej
-~~Eclipse~~-
post
Post #1





Goście







Witam czy ktos moglby pomoc?
  1. $data = "echo date('Y-m-d');";
  2. $time = "echo date('H-i');";


i wyskakuje
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 'Y-m-d');', 'echo date('H-i');')' at line 1
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
nospor
post
Post #2





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




Może napisz co chcesz zrobić i czemu.

Błąd co dostajesz to błąd bazy danych a nie php.
Go to the top of the page
+Quote Post
-~~Eclipse~~-
post
Post #3





Goście







Chce dodac date i czas do bazy danych:

  1. $sql = "INSERT INTO film_library(id, name, description, filmid, kind, data, czas) " .
  2. "VALUES ($id, '$name', '$description', '$aMatch[2]', '$kind', '$data', '$time')";
  3. $result = mysql_query($sql) or die(mysql_error());
Go to the top of the page
+Quote Post
peter13135
post
Post #4





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

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


$data = date('Y-m-d');
$time = date('H-i-s');


Dużo lepszym pomysłem jest trzymać wszystko jako znacznik czasu uniksa (funkcja time()) lub w polu DATETIME.
Po drugie, nie musisz generować czasu za pomocą skryptu PHP, możesz użyć MySqlowych now() lub current timestamp
Go to the top of the page
+Quote Post
nospor
post
Post #5





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




To po co echo? Echo służy do walenia czegoś do przeglądarki a nie do bazy. Poza tym date() to funkcja a nie tekst

  1. $data = date('Y-m-d');
  2. $time = date('H-i');
  3. $sql = "INSERT INTO film_library(id, name, description, filmid, kind, data, czas) " .
  4. "VALUES ($id, '$name', '$description', '$aMatch[2]', '$kind', '$data', '$time')";
  5. $result = mysql_query($sql) or die(mysql_error());
Go to the top of the page
+Quote Post
gargamel
post
Post #6





Grupa: Zarejestrowani
Postów: 278
Pomógł: 35
Dołączył: 25.06.2010

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


Nie
  1. $data = "echo date('Y-m-d');";
  2. $time = "echo date('H-i');";

a
  1. $data = date('Y-m-d');
  2. $time = date('H-i');


Sprawdź do czego służy echo.
Go to the top of the page
+Quote Post
-~~Eclipse~~-
post
Post #7





Goście







Dziekuje za pomoc (IMG:style_emoticons/default/smile.gif)
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: 25.08.2025 - 07:47