Advertisement
dbcalmada

policies.addrecord

Mar 28th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. if (!$_POST) {
  4.     die("No post data!");
  5. } else {
  6.     $sql = "INSERT INTO " . $_POST['table'] . " (";
  7.  
  8.     $field_count = (count($_POST) - 1);
  9.     $counter = 1;
  10.     foreach ($_POST as $key => $value) {
  11.         if ($key <> 'table') {
  12.             $sql .= $key;
  13.             if ($counter < $field_count) {
  14.                 $sql .= ",";
  15.             }
  16.         }
  17.         $counter += 1;
  18.     }
  19.    
  20.     $sql .= ") VALUES (";
  21.    
  22.    
  23.     $counter = 1;
  24.     foreach ($_POST as $key => $value) {
  25.         if ($key <> 'table') {
  26.             $sql .= "'" . $value . "'";
  27.             if ($counter < $field_count) {
  28.                 $sql .= ", ";
  29.             }
  30.             $counter += 1;
  31.         }
  32.     }
  33.     $sql .= ")";
  34.    
  35.     $result = mysqli_query($_SESSION['dbconn'],$sql);
  36.     if ($result) {
  37.             $_SESSION['message'] = array('info','Record added!');
  38.     } else {
  39.             $_SESSION['message'] = array('warning','Record not added!');
  40.     }
  41.     header("Location: " . SITEHOME);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement