SHARE
TWEET

Untitled

a guest Nov 9th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2.  
  3. <?php
  4.  
  5. $file = isset($_POST['filesave']);
  6.  
  7.  
  8.   if(isset($_POST['name']))
  9.   {
  10.     if(file_exists($file))
  11.     {
  12.       $f = fopen($file,'r+');
  13.       $content = fread($f, filesize($file));
  14.       ftruncate($f,0);
  15.       rewind($f);
  16.     }
  17.     else
  18.     {
  19.       $f = fopen($file,'w');
  20.       $content = "<?xml version='1.0' standalone='yes'?><dataplace></dataplace>";
  21.     }
  22.  
  23.     $xml = new SimpleXMLElement($content);
  24.     $name = $_POST['name'];
  25.     $surname = $_POST['surname'];
  26.     $phone = $_POST['phone'];
  27.     $relationship = $_POST['relationship'];
  28.     $eventCount = count($xml->event);
  29.     $xml->event[$eventCount]->name = $name;
  30.     $xml->event[$eventCount]->surname = $surname;
  31.     $xml->event[$eventCount]->phone = $phone;
  32.     $xml->event[$eventCount]->relationship = $relationship;
  33.  
  34.     fputs($f, $xml->asXML());
  35.     fclose($f);
  36.  
  37.   }
  38.  
  39.  
  40. ?>
  41.  
  42.  
  43. <html lang="pl" dir="ltr">
  44.   <head>
  45.     <meta charset="utf-8">
  46.     <title>Formularz gr. 1</title>
  47.   </head>
  48. <body>
  49.  
  50.    <form>
  51.       <fieldset>
  52.         <legend>Wydarzenie</legend>
  53.          
  54.          <p><label>Typ zapisu: <select name="filesave">
  55.             <option value="dataplace.xml" selected>XML</option>
  56.             <option value="dataplace.json">JSON</option>
  57.         </select></label></p>
  58.          
  59.          
  60.         <p><label>Nazwa: <input type="text" name="name"/></label></p>
  61.         <p><label>Nazwisko: <input type="text" name="surname" /></label></p>
  62.         <p><label>Numer telefonu: <input type="text" name="phone" /></label></p>
  63.         <p><label>Typ kontaktu: <select name="relationship">
  64.             <option value="praca">praca</option>
  65.             <option value="znajomi">znajomi</option>
  66.             <option value="rodzina">rodzina</option>
  67.         </select></label></p>
  68.          
  69.          
  70.           <?php echo $chuj; ?>
  71.          
  72.         <button type="submit" action="index.php" method="post">Zapisz</button>
  73.       </fieldset>
  74.     </form>
  75.  
  76.    
  77.      <?php
  78.       if(file_exists($file))
  79.       {
  80.         if(!isset($xml)){
  81.           $f = fopen($file,'r');
  82.           $content = fread($f, filesize($file));
  83.           fclose($f);
  84.           $xml = new SimpleXMLElement($content);
  85.         }
  86.  
  87.  
  88.  
  89.         $table = '<table><thead><tr><th>Imie</th><th>Nazwisko</th><th>Numer Telefonu</th><th>Typ kontaktu</th></tr></thead><tbody>';
  90.  
  91.         foreach($xml->event as $event)
  92.           $table .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',$event->name, $event->surname, $event->phone, $event->relationship);
  93.  
  94.         $table .= '</tbody></table>';
  95.  
  96.         echo $table;
  97.       }
  98.       else
  99.         echo 'Brak danych do wyświetlenia'
  100.  
  101.      ?>
  102.    
  103.    
  104. </body>
  105. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top