Advertisement
Guest User

t5-teans

a guest
Mar 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.84 KB | None | 0 0
  1. <?php # - edit_news.php
  2.  
  3. if (!defined('BASE_URL')) {
  4.  
  5.   // Need the BASE_URL, defined in the config file:
  6.   require_once('../includes/config.php');
  7.  
  8.   // Redirect to index page:
  9.   $url = BASE_URL . 'index.php';
  10.   header ("Location: $url");
  11.   exit;
  12.  
  13. } // IF (!defined('BASE_URL'))
  14.  if (isset($_POST['edit_team_submit'])) {
  15.    
  16.     echo "<pre>", print_r($_POST), "</pre>";
  17.  
  18.     $errors = [];
  19.  
  20.     $team_id = $_POST['team_id'];
  21.     $team_name = $_POST['team_name'];
  22.     $fk_game_id = $_POST['fk_game_id'];
  23.     $fk_country_id = $_POST['fk_country_id'];
  24.  
  25.     if ($team_name == "") {
  26.       $errors['team_name'] = "Team skal udfyldes";
  27.     }
  28.  
  29.       $query = "UPDATE teams
  30.                SET team_name = '$team_name', fk_game_id = '$fk_game_id', fk_country_id = '$fk_country_id'
  31.                WHERE team_id = $team_id";
  32.  
  33.       $db->query($query);
  34.       // header("Location: index.php?p=teams");    
  35.   }
  36.  
  37.   if (isset($_GET['team-id']) AND $_GET['team-id'] != "") {
  38.  
  39.       $team_id = $_GET['team-id'];
  40.  
  41.       $edit_post = get_team($team_id);
  42.  
  43.       if ($edit_post) {
  44.  
  45.        // echo "<pre>", print_r($edit_post), "</pre>";
  46.  
  47.         $team_name = $edit_post-> team_name;
  48.         $fk_country_id = $edit_post-> fk_country_id;
  49.         $fk_game_id = $edit_post-> fk_game_id;
  50.         $country_title = $edit_post-> title;
  51.         $game_title = $edit_post-> game_title;
  52.  
  53. ?>
  54. <section class="clearfix" id="content">
  55.         <!-- Render JavaScript alerts here -->
  56.         <div class="alert-area"></div><a class="page-head" href="?p=teams"><i class="fa fa-newspaper-o"></i> News</a>
  57.         <div class="page page-news page-news-admin-form">
  58.             <form role="form" class="form-horizontal" method="post">
  59.               <input type="hidden" name="team_id" value="<?php echo $team_id; ?>">
  60.                 <?php
  61.                     if (isset($errors['team_name'])) {
  62.                       echo $errors['team_name'];
  63.                     }
  64.                 ?>
  65.                 <div class="form-group">
  66.                     <label class="col-sm-3 control-label" for="team_name">Team</label>
  67.                     <div class="col-sm-9">
  68.                         <input id="team_name" name="team_name" type="text" value="<?php echo $team_name; ?>">
  69.                     </div>
  70.                 </div>
  71.                 <div class="form-group">
  72.                   <label class="col-sm-3 control-label" for="Country">Country</label>
  73.                   <div class="col-sm-9">
  74.                     <select id="Country" name="Country" class="form-control">
  75.                       <option value="na" selected="">Choose:</option>
  76.                         <?php
  77.                              $sql1 = "SELECT * FROM countries";
  78.                           $result1 = mysqli_query($db, $sql1);
  79.  
  80.                           while ($row1 = mysqli_fetch_assoc($result1)) {
  81.  
  82.                             // echo "<pre>", print_r($row1), "</pre>";
  83.  
  84.                             $fk_country_id = $row1['id'];
  85.                             $country_title = $row1['title'];      
  86.                           echo '<option value="'. $fk_country_id .'">'. $country_title .'</option>';
  87.                           }
  88.                         ?>
  89.                     </select>
  90.                   </div>
  91.                 </div>
  92.                 <div class="form-group">
  93.                   <label class="col-sm-3 control-label" for="Game">Game</label>
  94.                   <div class="col-sm-9">
  95.                     <select id="game" name="game" class="form-control">
  96.                       <option value="na" selected="">Choose:</option>
  97.                         <?php
  98.                             $sql = "SELECT * FROM games ORDER BY game_id ASC";
  99.                             $result = mysqli_query($db, $sql);
  100.  
  101.                             while ($row = mysqli_fetch_assoc($result)){
  102.                               $fk_game_id = $row['game_id'];
  103.                               $game_title = $row['game_title'];
  104.                                      
  105.                             echo '<option value="'. $fk_game_id .'">'. $game_title .'</option>';
  106.                                      
  107.                             }
  108.  
  109.                           ?>
  110.                     </select>
  111.                   </div>
  112.                 </div>
  113.                 <div class="form-actions">
  114.                     <button type="submit" name="edit_team_submit" class="btn btn-default"><i class="fa fa-save"></i> Save</button>
  115.                     <button class="btn btn-default" type="reset"><i class="fa fa-undo"></i> Reset</button>
  116.                 </div>
  117.             </form>
  118.         </div>
  119.     </section>
  120.  
  121.     <?php
  122.       } else {
  123.           header("Location: index.php");
  124.     } // END IF ELSE ($edit_post)
  125.  
  126.     } else {
  127.     header("Location: index.php");
  128.   } // END IF ELSE (isset($_GET['post-id']) AND $_GET['post-id'] != "")
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement