Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <?php
- $file = isset($_POST['filesave']);
- if(isset($_POST['name']))
- {
- if(file_exists($file))
- {
- $f = fopen($file,'r+');
- $content = fread($f, filesize($file));
- ftruncate($f,0);
- rewind($f);
- }
- else
- {
- $f = fopen($file,'w');
- $content = "<?xml version='1.0' standalone='yes'?><dataplace></dataplace>";
- }
- $xml = new SimpleXMLElement($content);
- $name = $_POST['name'];
- $surname = $_POST['surname'];
- $phone = $_POST['phone'];
- $relationship = $_POST['relationship'];
- $eventCount = count($xml->event);
- $xml->event[$eventCount]->name = $name;
- $xml->event[$eventCount]->surname = $surname;
- $xml->event[$eventCount]->phone = $phone;
- $xml->event[$eventCount]->relationship = $relationship;
- fputs($f, $xml->asXML());
- fclose($f);
- }
- ?>
- <html lang="pl" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>Formularz gr. 1</title>
- </head>
- <body>
- <form>
- <fieldset>
- <legend>Wydarzenie</legend>
- <p><label>Typ zapisu: <select name="filesave">
- <option value="dataplace.xml" selected>XML</option>
- <option value="dataplace.json">JSON</option>
- </select></label></p>
- <p><label>Nazwa: <input type="text" name="name"/></label></p>
- <p><label>Nazwisko: <input type="text" name="surname" /></label></p>
- <p><label>Numer telefonu: <input type="text" name="phone" /></label></p>
- <p><label>Typ kontaktu: <select name="relationship">
- <option value="praca">praca</option>
- <option value="znajomi">znajomi</option>
- <option value="rodzina">rodzina</option>
- </select></label></p>
- <?php echo $chuj; ?>
- <button type="submit" action="index.php" method="post">Zapisz</button>
- </fieldset>
- </form>
- <?php
- if(file_exists($file))
- {
- if(!isset($xml)){
- $f = fopen($file,'r');
- $content = fread($f, filesize($file));
- fclose($f);
- $xml = new SimpleXMLElement($content);
- }
- $table = '<table><thead><tr><th>Imie</th><th>Nazwisko</th><th>Numer Telefonu</th><th>Typ kontaktu</th></tr></thead><tbody>';
- foreach($xml->event as $event)
- $table .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',$event->name, $event->surname, $event->phone, $event->relationship);
- $table .= '</tbody></table>';
- echo $table;
- }
- else
- echo 'Brak danych do wyświetlenia'
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement