![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Mam skrypt addevent.php
[php:1:83746fede9]<?php <html> <head> <title>Add Event</title> </head> <body> <font size="+2"><b>Add Event</b></font><br><br> <?php if ($action == "add") { include("common.php"); $link = dbConnect(); if ($year < 60) { $year += 2000; } else if ($year < 100) { $year += 1900; } $month--; $event = nl2br($event); $event = eregi_replace("[nr]+", "", $event); $query = "INSERT INTO $table (year, month, day, title, event) VALUES ($year, $month, $day, '$title', '$event')"; // Execute query $result = mysql_query($query); if ($result) { print "<font color="#0000ff">Event added</font><br>n"; } else { // Otherwise, inform user of failure print "<font color="#ff0000">Couldn't add event</font><br>n"; } mysql_close($link); } ?> <form action="addevent.php" METHOD="post"> <table border="1" cellspacing="2" cellpadding="3"> <tr> <td>Date</td> <td> Day <input type="number" name="day" size="2"> Month <input type="number" name="month" size="2"> Year <input type="number" name="year" size="4"> </td> </tr> <tr> <td>Title</td> <td><input type="text" name="title" size="50"></td> </tr> <tr> <td>Event</td> <td><textarea name="event" cols="50" rows="5"></textarea></td> </tr> <tr> <td colspan="2"> <input type="hidden" name="action" value="add"> <input type="submit" value="Add Event"> </td> </tr> </table> </form> </body> ?> </html> [/php:1:83746fede9] i skrypt common.php [php:1:83746fede9] <? $dbHost = "localhost"; $dbUser = "nazwa"; $dbPass = "nazwa"; $dbName = "nazwa"; $table = "nazwa"; function dbConnect() { global $dbHost; global $dbUser; global $dbPass; global $dbName; $link = @mysql_connect($dbHost, $dbUser, $dbPass); if (!$link) { fail("Couldn't connect to database server"); } if (!@mysql_select_db($dbName)) { fail("Couldn't find database $dbName"); } return $link; } function fail($errorMsg) { $errorMsg = urlencode($errorMsg); print "&result=Fail&errormsg=$errorMsg"; exit; } ?> Dlaczego nie dodają mi się rekordy do tabeli. Z wiersza poleceń działa. Czy moga to być jakies problemy z ustawieniami? Bo testowałem już (niestety bardzo długo) z różnymi skryptami. ?>[/php:1:83746fede9] |
|
|
![]()
Post
#2
|
|
![]() Grupa: Przyjaciele php.pl Postów: 120 Pomógł: 0 Dołączył: 29.11.2003 Skąd: Tarnów Ostrzeżenie: (0%) ![]() ![]() |
zmienne ktore tam uzywasz ($action, $date itd.) wychodza z formularza a wiec nie [php:1:00f1e7ce12]<?php
if ($action == "add") { ?>[/php:1:00f1e7ce12] tylko[php:1:00f1e7ce12]<?php if ($_POST['action'] == "add") { ?>[/php:1:00f1e7ce12] i to samo z reszta... latwiej bedzie uproscic czyli [php:1:00f1e7ce12]<?php $action = $_POST['action']; ?>[/php:1:00f1e7ce12] moze pomoc (nie jestem pewien na 100%) moje ciut slepawe oko nie widzi wiecej bledow... :wink: |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Dzieki.
Działa. Jestem tepy. Jak będe mógł pomóc z Flasha to bardzo chętnie. Teraz zabieram się do przejmowania danych z bazy przez Flasha. Więc pewnie jeszcze się odezwę ... Ale moze jutro ... |
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
NIestety pospieszyłem sie
Wywaliło mi Couldn't add event [php:1:455896ad15]<?php $result = mysql_query($query); // If the query was successfull if ($result) { // Output success msg print "<font color="#0000ff">Event added</font><br>n"; } else { // Otherwise, inform user of failure print "<font color="#ff0000">Couldn't add event</font><br>n"; } ?>[/php:1:455896ad15] |
|
|
![]()
Post
#5
|
|
![]() Grupa: Przyjaciele php.pl Postów: 660 Pomógł: 0 Dołączył: 28.08.2002 Skąd: Starachowice Ostrzeżenie: (0%) ![]() ![]() |
Proszę wyedytować wątek i zmienić temat. Do tego czasu proszę nie odpowiadać w tym temacie.
|
|
|
![]()
Post
#6
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Czy bład jest tutaj:
[php:1:d2259e9625]<?php $query = "INSERT INTO $table (year, month, day, title, event) VALUES ($year, $month, $day, '$title', '$event')"; ?>[/php:1:d2259e9625] |
|
|
![]()
Post
#7
|
|
![]() Grupa: Zarejestrowani Postów: 445 Pomógł: 0 Dołączył: 21.12.2003 Skąd: Tomaszów Lubelski Ostrzeżenie: (10%) ![]() ![]() |
Spróbuj tak:
[php:1:31e83605ee]<?php $query = "INSERT INTO ".$table." (year, month, day, title, event) VALUES (".$year.", ".$month.", ".$day.", '".$title."', '".$event."')"; ?>[/php:1:31e83605ee] -------------------- Don't worry, be happy!
Gadu-Gadu: 1687784 Darmowe komponenty na stronę WWW - licznik księga gości shoutbox chat kalendarz data godzina imieniny IP host przeglądarka odwiedzającego ankieta sonda |
|
|
![]()
Post
#8
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Niestety ten sam błąd - nie dodaje.
|
|
|
![]()
Post
#9
|
|
![]() Grupa: Przyjaciele php.pl Postów: 120 Pomógł: 0 Dołączył: 29.11.2003 Skąd: Tarnów Ostrzeżenie: (0%) ![]() ![]() |
powiedz mi gdzie tu jest polaczenie z baza? bo albo moje slepawe oczy nie widza albo ty tylko przypisales do zmiennej:[php:1:98dedead72]<?php
$link = dbConnect(); ?>[/php:1:98dedead72] a nie uzyles tej funkzji :? |
|
|
![]()
Post
#10
|
|
![]() Grupa: Zarejestrowani Postów: 445 Pomógł: 0 Dołączył: 21.12.2003 Skąd: Tomaszów Lubelski Ostrzeżenie: (10%) ![]() ![]() |
Spróbuj tego:
[php:1:685a7afbae]<?php $host = "localhost"; $user = ""; $haslo = ""; $baza = ""; $table = ""; $year = ""; $month = ""; $day = ""; $title = ""; $event = ""; if (!$id = mysql_connect($host, $user, $haslo)) echo mysql_errno($id) . ": " .mysql_error($id). "n"; if (!mysql_select_db($baza, $id)) echo mysql_errno($id) . ": " .mysql_error($id). "n"; $query = "INSERT INTO ".$table." (year, month, day, title, event) VALUES (".$year.", ".$month.", ".$day.", '".$title."', '".$event."')"; if (!$wynik = mysql_query($query)) echo mysql_errno($id) . ": " .mysql_error($id). "n"; ?>[/php:1:685a7afbae] Umieść to w nowym pliku i uzupełnij zmienne. -------------------- Don't worry, be happy!
Gadu-Gadu: 1687784 Darmowe komponenty na stronę WWW - licznik księga gości shoutbox chat kalendarz data godzina imieniny IP host przeglądarka odwiedzającego ankieta sonda |
|
|
![]()
Post
#11
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Tak - teraz dodaje.
Lecz jak połączyć to z tymi ograniczeniami dotyczącymi dat i polami input? |
|
|
![]()
Post
#12
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Spróbowałem tak:
[php:1:7c7456a0c8]<?php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"> <title>Add Event</title> </head> <body> <font size="+2"><b>Add Event</b></font><br><br> <?php if ($_POST['action'] == "add") { $host = "localhost"; $user = "janusz"; $haslo = "zywert"; $baza = "phpforflash"; $table = "events"; $id = mysql_connect($host, $user, $haslo); if (!mysql_select_db($baza, $id)) echo mysql_errno($id) . ": " . mysql_error($id). "n"; $query = "INSERT INTO ".$table." (year, month, day, title, event) VALUES (".$year.", ".$month.", ".$day.", '".$title."', '".$event."')"; if (!$wynik = mysql_query($query)) echo mysql_errno($id) . ": " . mysql_error($id). "n"; } ?> <form action="test.php" METHOD="post"> <table border="1" cellspacing="2" cellpadding="3"> <tr> <td>Date</td> <td> Day <input type="number" name="day" size="2"> Month <input type="number" name="month" size="2"> Year <input type="number" name="year" size="4"> </td> </tr> <tr> <td>Title</td> <td><input type="text" name="title" size="50"></td> </tr> <tr> <td>Event</td> <td><textarea name="event" cols="50" rows="5"></textarea></td> </tr> <tr> <td colspan="2"> <input type="hidden" name="action" value="add"> <input type="submit" value="Add Event"> </td> </tr> </table> </form> </body> </html> ?>[/php:1:7c7456a0c8] i otrzymałem to: 1064: You have an error in your SQL syntax near ' , , '', '')' at line 1 |
|
|
![]()
Post
#13
|
|
![]() Grupa: Zarejestrowani Postów: 445 Pomógł: 0 Dołączył: 21.12.2003 Skąd: Tomaszów Lubelski Ostrzeżenie: (10%) ![]() ![]() |
Spróbuj zmienić tą linię:
[php:1:6be8337016]<?php $query = "INSERT INTO ".$table." (year, month, day, title, event) VALUES ('".$year."', '".$month."', '".$day."', '".$title."', '".$event."')"; ?>[/php:1:6be8337016] -------------------- Don't worry, be happy!
Gadu-Gadu: 1687784 Darmowe komponenty na stronę WWW - licznik księga gości shoutbox chat kalendarz data godzina imieniny IP host przeglądarka odwiedzającego ankieta sonda |
|
|
![]()
Post
#14
|
|
Grupa: Zarejestrowani Postów: 13 Pomógł: 0 Dołączył: 14.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Zminiłem kod na taki i zamist danych w bazie powstaja puste pola
Nie wypełnia tabeli Nie wiem co zrobić [php:1:08994c89b1]<?php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"> <title>Add Event</title> </head> <body> <font size="+2"><b>Add Event</b></font><br><br> <?php if ($_POST['action'] == "add") { $host = "localhost"; $user = "janusz"; $haslo = "zywert"; $baza = "phpforflash"; $table = "events"; $id = mysql_connect($host, $user, $haslo); if (!mysql_select_db($baza, $id)) echo mysql_errno($id) . ": " . mysql_error($id). "n"; $query = "INSERT INTO ".$table." (year, month, day, title, event) VALUES ('".$year."', '".$month."', '".$day."', '".$title."', '".$event."')"; if (!$wynik = mysql_query($query)) echo mysql_errno($id) . ": " . mysql_error($id). "n"; } ?> <form action="test.php" METHOD="post"> <table border="1" cellspacing="2" cellpadding="3"> <tr> <td>Date</td> <td><input type="text" name="day" size="50"></td> </tr> <tr> </tr> <td>Month</td> <td><input type="text" name="month" size="50"></td> </tr> <tr></tr> <td>Year</td> <td> <input type="text" name="year" size="50"></td> </tr> <tr> <td>Title</td> <td><input type="text" name="title" size="50"></td> </tr> <tr> <td>Event</td> <td><textarea name="event" cols="50" rows="5"></textarea></td> </tr> <tr> <td colspan="2"> <input type="hidden" name="action" value="add"> <input type="submit" value="Add Event"> </td> </tr> </table> </form> </body> </html> ?>[/php:1:08994c89b1] |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 19.07.2025 - 01:45 |