Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.62 KB | None | 0 0
  1. <?php # create_links.php 8.5
  2.  
  3. session_start(); // Start the session.
  4.  
  5. // If no session value is present, redirect the user:
  6.  
  7. if (!isset($_SESSION['user_id'])) {
  8.  
  9.     require_once ('includes/login_functions.inc.php');
  10.  
  11.     $url = absolute_url();
  12.  
  13.     header("Location: $url");
  14.  
  15.     exit(); // Quit the script.
  16.  
  17. }
  18.  
  19.  
  20.  
  21. $page_title = 'New Link';
  22.  
  23. include ('includes/header.html');
  24.  
  25.  
  26.  
  27. // Check if the form has been submitted:
  28.  
  29. if (isset($_POST['submitted'])) {
  30.  
  31.     require_once ('xxx'); // Connect to the db.
  32.  
  33.     $errors = array(); // Initialise an error array.
  34.  
  35.  
  36.     // Check for a title:
  37.  
  38.     if (empty($_POST['title'])) {
  39.  
  40.        $errors[] = 'You forgot to enter the link title.';
  41.  
  42.     } else {
  43.  
  44.        $title = mysqli_real_escape_string($dbc, trim($_POST['$title']));
  45.  
  46.     }
  47.  
  48.  
  49.  
  50.     // Check for an intro:
  51.  
  52.     if (empty($_POST['intro'])) {
  53.  
  54.        $errors[] = 'You forgot to enter the link intro.';
  55.  
  56.     } else {
  57.  
  58.        $intro = mysqli_real_escape_string($dbc, trim($_POST['$intro']));
  59.  
  60.     }
  61.  
  62.  
  63.  
  64.     // Check for an entry:
  65.  
  66.     if (empty($_POST['entry'])) {
  67.  
  68.        $errors[] = 'You forgot to enter the link entry text.';
  69.  
  70.     } else {
  71.  
  72.        $entry = mysqli_real_escape_string($dbc, trim($_POST['$entry']));
  73.  
  74.     }
  75.  
  76.     // Check for an link:
  77.  
  78.     if (empty($_POST['link'])) {
  79.  
  80.        $errors[] = 'You forgot to enter the link.';
  81.  
  82.     } else {
  83.  
  84.        $entry = mysqli_real_escape_string($dbc, trim($_POST['$link']));
  85.  
  86.     }
  87.  
  88.  
  89.  
  90.     if (empty($errors)) { // If everything is ok.
  91.  
  92.  
  93.  
  94.         // Register the user in the database...
  95.  
  96.  
  97.  
  98.         // Make the query:
  99.  
  100.         $q = "INSERT INTO links (title, intro, entry, link, creation_date) VALUES ('$title', '$intro', '$entry', '$link', NOW() )";
  101.  
  102.         $r = @mysqli_query ($dbc, $q); // Run the query.
  103.  
  104.         if ($r) { // If it ran ok.
  105.  
  106.  
  107.  
  108.            // Print a message:
  109.  
  110.            echo '<h1>Thank you!</h1>
  111.  
  112.         <p>The link is now created. There will be a log in later.</p><p><br /></p>';
  113.  
  114.  
  115.  
  116.         } else { // If it did not run ok.
  117.  
  118.  
  119.  
  120.            // Public message:
  121.  
  122.            echo '<h1>System Error</h1>
  123.  
  124.            <p class="error"> The link could not be created due to a system error. We apologise for any inconvenience. </p>';
  125.  
  126.  
  127.  
  128.             // Debugging message:
  129.  
  130.             echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' .$q . '</p>';
  131.  
  132.  
  133.  
  134.         } // End of if ($r) IF.
  135.  
  136.        
  137.  
  138.        
  139.  
  140.  
  141.  
  142.         // Include the footer and quit the script:
  143.  
  144.         include ('pook_includes/footer.html');
  145.  
  146.         exit();
  147.  
  148.  
  149.  
  150.     } else { // Report the errors.
  151.  
  152.  
  153.  
  154.         echo '<h1>Error!</h1>
  155.  
  156.         <p class="error">The following error(s) occured:<br />';
  157.  
  158.         foreach ($errors as $msg) { // Print each error
  159.  
  160.            echo " - $msg<br />\n";
  161.  
  162.         }
  163.  
  164.         echo '</p><p>Please again.</p><p><br /></p>';
  165.  
  166.    
  167.  
  168.     } // End of if (empty($errors)) IF.
  169.  
  170.     mysqli_close($dbc); // Close the database connection
  171.  
  172.  
  173.  
  174. } // End of the main a submit conditional.
  175.  
  176. ?>
  177.  
  178. <h1>New Link</h1>
  179.  
  180. <form action="create_links.php" method="POST">
  181.  
  182.    <p>Intro: <input type="text" name="intro" size="40" maxlength="60" value="<?php if (isset($_POST['intro'])) echo $_POST['intro']; ?>" /></p>
  183.  
  184.    <p>Entry:<br /><textarea name="entry" id="entry" rows="15" cols="80"><?php if (isset($_POST['entry'])) echo $_POST['entry']; ?></textarea></p>
  185.    
  186.    <p>Title: <input type="text" name="title" size="20" maxlength="40" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /></p>
  187.    
  188.    <p>Link: <input type="text" name="link" size="20" maxlength="40" value="<?php if (isset($_POST['link'])) echo $_POST['link']; ?>" /></p>
  189.  
  190.  
  191.  
  192.    <p><input type="submit" name="submit" value="Create Page" /></p>
  193.  
  194.    <input type="hidden" name="submitted" value="TRUE" />
  195.  
  196. </form>
  197.  
  198.  
  199. <?php
  200.  
  201. include ('includes/footer.html');
  202.  
  203. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement