Save new food
Search by Author name
Informatsioon
Name |
Price |
Book |
John Obrey | 12.05$ | Brief Lives |
Arthur Doyle | 5.03$ | The parasite |
Agatha Christie | 17.2$ | The last Seance |
William Somerset | 19.4$ | Rain |
John Taylor | 18.7$ | Lucky Dip |
Lewis Carroll | 10.2$ | Haddocks Eyes |
eee | w$ | eee |
asd | asdad$ | asdsa |
| $ | |
| $ | |
| $ | |
| $ | b |
| $ | brief |
john | $ | |
. | $ | |
Link XML fail
<?php
if(isset($_POST['submit'])){
$xmlDoc = new DOMDocument("1.0","UTF-8");
$xmlDoc->preserveWhiteSpace = false;
$xmlDoc->load('xmlbook.xml');
$xmlDoc->formatOutput = true;
$xml_root = $xmlDoc->documentElement;
$xmlDoc->appendChild($xml_root);
$xml_toode = $xmlDoc->createElement("catalog");
$xmlDoc->appendChild($xml_toode);
$xml_root->appendChild($xml_toode);
unset($_POST['submit']);
foreach($_POST as $voti=>$vaartus){
if($voti == "protein" or $voti == "carbs" or $voti == "fats"){
$kirje = $xmlDoc->createElement($voti,$vaartus);
continue;
}
$kirje = $xmlDoc->createElement($voti,$vaartus);
$xml_toode->appendChild($kirje);
}
$xmlDoc->save('xmlbook.xml');
}
?>
<head>
<link rel="stylesheet" href="table.css">
</head>
<style>
header{
margin-top: 15px;
color: blue;
font-family: "Times New Roman Blue";
font-style: italic;
margin-bottom: 50px;
text-align: center;
font-size: 30px;
}
</style>
<header>
<h1>XML andmete salvestamine PHP abil</h1>
</header>
<div id="mainDiv">
<h2>Save new food</h2>
<table>
<form action="" method="post">
<tr>
<td><label for="name">Name: </label></td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td><label for="book">Book: </label></td>
<td><input type="text" name="book" id="book"></td>
</tr>
<tr>
<td><label for="price">Price: </label></td>
<td><input type="text" name="price" id="price"></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Sisesta"></td>
</tr>
</form>
</table>
<h2>Search by Author name</h2>
<form action="?" method="post">
<input type="text" name="search" placeholder="name..."><br>
<button type="submit">Search</button>
</form>
<h2>Informatsioon</h2>
<table id="show">
<tr>
<th>Name</th>
<th>Price</th>
<th>Book</th>
</tr>
<?php
$data = simplexml_load_file('xmlbook.xml');
foreach ($data->catalog as $catalog){
if(!empty($_POST["search"])){
if(strpos(strtolower($catalog->name), strtolower($_POST["search"])) === false)
continue;
}
echo "<tr>";
echo "<td>$catalog->name</td>";
echo "<td>$catalog->price"."$"."</td>";
echo "<td>$catalog->book".""."</td>";
echo "</tr>";
}
?>
</table>
<a target="_blank" href="xmlbook.xml">Link XML fail</a><br>
<button onclick="myFunction()">Показать исходный код</button>
<div style="display: none;" id="myDIV">
<?php highlight_file("./book.php") ?>
</div>
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
</div>