SHARE
TWEET

Untitled

a guest Oct 13th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <title>Quote of the day : Version 2</title>
  5. </head>
  6. <body>
  7. <h4>Quote of the day ... [version 2]</h4>
  8.  
  9. <?php
  10. echo "<h4>".date("D M d Y")."</h4>";
  11.  
  12. //Store the contents of the file quotes.dat into $content.
  13. $content = file('quotes.dat');
  14.  
  15. // count how many lines in the file  
  16. $numLines = count($content);
  17.  
  18. // generate a random number between 1 and $numLines
  19. $line = rand(0, ($numLines-1));
  20.    
  21.         // get the data into an array, each value delimited by a pipe.
  22.         $data = explode("|", $content[$line]);
  23.        
  24.         // print the image out.
  25.         echo "<img src='$data[4]' style='height: 100px; width: 100px;'>";
  26.        
  27.         //print out the category.
  28.         echo "<h1>$data[5]</h1>";
  29.        
  30.         // print out the quote.
  31.         echo "<p style='width: 600px;'>";
  32.         echo htmlentities($data[0]);
  33.         echo "</p>";
  34.         echo "<p style=\"text-align:right\"><a href=\"$data[3]\">$data[1]</a> ($data[2])</p>";
  35.    
  36.  
  37.  
  38. //Form will all the data relating to quotes.
  39. //Note in the form tag, 'action' and 'method' are key. Action is where the webpage will be directed after the sumbit button has been pressed, in this case it will redirected to the same page.
  40. //The method is important otherwise the values will not be sent into the POST array.  
  41. ?>
  42. <form action="quote_v2.php" method="POST" style="border: 2px solid black;">
  43. <p style="color: red;">Enter your quote</p>
  44. <input type="text" name="quote" placeholder="Enter the quote here.">
  45. <input type="text" name="source" placeholder="Enter the author or source name here.">
  46. <input type="text" name="dob_dod" placeholder="Enter the dob-dod here.">
  47. <input type="text" name="wp_link" placeholder="Enter the link to the sources wikipedia page here.">
  48. <input type="text" name="wp_img" placeholder="Enter the link to the sources image on wikipedia here.">
  49. <select name="category">
  50. <option value="Romantic">Romantic</option>
  51. <option value="Comedy"> Comedy </option>
  52. <option value="War"> War </option>
  53. </select>
  54. <input type="submit" name="submit">
  55. </form>
  56.  
  57. <?php
  58.    
  59.     if (isset($_POST['submit'])){ //If the sumbit button has been clicked.
  60.    
  61.         //Set all the varibles from the POST data of the form.
  62.         $quote = $_POST['quote'];
  63.         $source = $_POST['source'];
  64.         $dob_dod = $_POST['dob_dod'];
  65.         $wp_link = $_POST['wp_link'];
  66.         $wp_img = $_POST['wp_img'];
  67.         $category = $_POST['category'];
  68.        
  69.         //Ammend them all together delimited by a pipe to keep in the same format.
  70.         $appendString = "\n" . $quote . "|" . $source . "|" . $dob_dod . "|" . $wp_link . "|" . $wp_img . "|" . $category;
  71.        
  72.         //Append them to the text file.
  73.         file_put_contents('quotes.dat', $appendString, FILE_APPEND);
  74.    
  75.     }
  76. ?>
  77.  
  78. </body>
  79. </html>
RAW Paste Data
Top