Formularz Dodawania, Edycji, Usuwania danych z kalendarza
jest to formularz, dodawania , edycji i usuwania wydarzeń z kalendarz , którego skrypt napisał inny użytkownik.
Listing
<? $ac=trim($_REQUEST["ac"]);
$id = trim($_REQUEST["id"]);
$data=$_POST["data"];
$title= $_POST["title"];
$opis= $_POST["opis"];
$mark= $_POST["mark"];
$skrypt = $_SERVER["PHP_SELF"];
if ($ac=="edit" and $id<>"") {
$db=mysql_connect("localhost","login","haslo");
if ($db) {
$result=mysql_select_db("nazwa_bazy");
if ($result) {
$result = mysql_query("SELECT * FROM event WHERE id=$id;");
if($result) {
$pole=mysql_fetch_array($result);
$id=$pole[id];
$data=$pole[data];
$title=$pole[title];
$opis=$pole[opis];
}
}
mysql_close($db);
}
$ac="form";
}
echo <<< KONIEC
<form id="form1" name="form1" method="post" action="$skrypt">
<input type="hidden" name="ac" value="add">
<input type="hidden" name="id" value="$id">
<p>Data
<input type="text" name="data" value="$data" id="datepicker">
<br />
<br />
Even Title
<input name="title" value="$title" type="text" id="title" size="45" />
<br />
<br />
Describe
<textarea name="opis" value="$opis" id="opis" cols="45" rows="5">$opis</textarea>
</label>
</p>
<p>Color Mark :
<label>
<input type="radio" name="mark" id="red" value="0" />
red</label>
<label>
<input type="radio" name="mark" id="blue" value="1" />
blue</label>
<label>
<input type="radio" name="mark" id="pink" value="2" />
pink</label>
</p>
<p>
<label>
<input type="submit" name="add" id="submit" value="add" />
</label>
</p>
</form>
KONIEC;
//if($ac=="add") {
if ($_POST['add'] == "add") {
$db=mysql_connect("localhost","login","haslo");
$result=mysql_select_db("nazwa_bazy");
if ($result and $id=="") {
$result=mysql_query("INSERT INTO event
(data, title, opis, mark)
VALUES
('$data','$title','$opis','$mark')");
}
if ($result and $id<>"") {
$result=mysql_query("UPDATE event SET data='$data',title='$title', opis='$opis',mark='$mark' WHERE id=$id");
}
if ($result) echo "<br>ADD <br>";
else echo "<br>Error ".mysql_error();
}
if ($ac=="delete" and $id<>"") {
$db=mysql_connect("localhost","login","haslo");
if ($db) {
$result=mysql_select_db("nazwa_bazy");
if ($result) {
$result=mysql_query("DELETE FROM event WHERE id=$id LIMIT 1");
}
if ($result) echo "<br>Event was remove<br>";
else echo "<br>Error ".mysql_error();
mysql_close($db);
}
}
// ============ LISTOWANIE WYNIKÓW Z BAZY KALENDARZ, PLUS OPCJE EDYCJI I KASOWANIA ================================
$db=mysql_connect("localhost","login","haslo");
mysql_select_db("nazwa_bazy",$db);
$sql = "SELECT * FROM event ORDER BY data";
$result = mysql_query($sql);
while($rows = mysql_fetch_row($result)){
echo "$rows[1]||$rows[2]||$rows[3]||<a href=\"$skrypt?ac=edit&id=$rows[0]\">[EDIT]</a><a href=\"$skrypt?ac=delete&id=$rows[0]\">[DELETE]</a><br>";
}
?>
$id = trim($_REQUEST["id"]);
$data=$_POST["data"];
$title= $_POST["title"];
$opis= $_POST["opis"];
$mark= $_POST["mark"];
$skrypt = $_SERVER["PHP_SELF"];
if ($ac=="edit" and $id<>"") {
$db=mysql_connect("localhost","login","haslo");
if ($db) {
$result=mysql_select_db("nazwa_bazy");
if ($result) {
$result = mysql_query("SELECT * FROM event WHERE id=$id;");
if($result) {
$pole=mysql_fetch_array($result);
$id=$pole[id];
$data=$pole[data];
$title=$pole[title];
$opis=$pole[opis];
}
}
mysql_close($db);
}
$ac="form";
}
echo <<< KONIEC
<form id="form1" name="form1" method="post" action="$skrypt">
<input type="hidden" name="ac" value="add">
<input type="hidden" name="id" value="$id">
<p>Data
<input type="text" name="data" value="$data" id="datepicker">
<br />
<br />
Even Title
<input name="title" value="$title" type="text" id="title" size="45" />
<br />
<br />
Describe
<textarea name="opis" value="$opis" id="opis" cols="45" rows="5">$opis</textarea>
</label>
</p>
<p>Color Mark :
<label>
<input type="radio" name="mark" id="red" value="0" />
red</label>
<label>
<input type="radio" name="mark" id="blue" value="1" />
blue</label>
<label>
<input type="radio" name="mark" id="pink" value="2" />
pink</label>
</p>
<p>
<label>
<input type="submit" name="add" id="submit" value="add" />
</label>
</p>
</form>
KONIEC;
//if($ac=="add") {
if ($_POST['add'] == "add") {
$db=mysql_connect("localhost","login","haslo");
$result=mysql_select_db("nazwa_bazy");
if ($result and $id=="") {
$result=mysql_query("INSERT INTO event
(data, title, opis, mark)
VALUES
('$data','$title','$opis','$mark')");
}
if ($result and $id<>"") {
$result=mysql_query("UPDATE event SET data='$data',title='$title', opis='$opis',mark='$mark' WHERE id=$id");
}
if ($result) echo "<br>ADD <br>";
else echo "<br>Error ".mysql_error();
}
if ($ac=="delete" and $id<>"") {
$db=mysql_connect("localhost","login","haslo");
if ($db) {
$result=mysql_select_db("nazwa_bazy");
if ($result) {
$result=mysql_query("DELETE FROM event WHERE id=$id LIMIT 1");
}
if ($result) echo "<br>Event was remove<br>";
else echo "<br>Error ".mysql_error();
mysql_close($db);
}
}
// ============ LISTOWANIE WYNIKÓW Z BAZY KALENDARZ, PLUS OPCJE EDYCJI I KASOWANIA ================================
$db=mysql_connect("localhost","login","haslo");
mysql_select_db("nazwa_bazy",$db);
$sql = "SELECT * FROM event ORDER BY data";
$result = mysql_query($sql);
while($rows = mysql_fetch_row($result)){
echo "$rows[1]||$rows[2]||$rows[3]||<a href=\"$skrypt?ac=edit&id=$rows[0]\">[EDIT]</a><a href=\"$skrypt?ac=delete&id=$rows[0]\">[DELETE]</a><br>";
}
?>
Dodano przez: ghost2k8 Ranga: 0 Punktów: 0
Komentarze użytkowników
Dzięki za kod.
autor: shczepan | 12439 | 2011-05-15 12:02:43
:: Losowe artykuły
:: Wymiana linków
Modowe inspiracje |
Android Gry i Aplikacje |
ZaplanujTransport.pl: Przeprowadzki, transport, aukcje |
Logo dla firmy |
Change Tires - Car Weather Forecast Reminder |
Laminas: MVC Framework for PHP |
IT Books Reviews and Programming: JS, JAVA, PHP, ANDROID, CSS |
Katalog roślin |
Programming articles: JAVA, PHP, C++, Python, JavaScript |
Kancelaria Adwokacka Łukasz Huszno