Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <?php
  2. include("config.php");
  3. $conn=pg_connect("host=".host." user=".user." password=".pass." dbname=".database);
  4.    
  5. function get_title($id=0)
  6. {
  7.     global $conn;
  8.     $sql="SELECT title as count FROM proxy_selection where id=".$id;
  9.     $result=pg_Exec($conn,$sql);
  10.     return pg_fetch_result($result,0,"title");
  11. }  
  12.    
  13. function get_desc($id=0)
  14. {
  15.     global $conn;
  16.     $sql="SELECT description as count FROM proxy_selection where id=".$id;
  17.     $result=pg_Exec($conn,$sql);
  18.     return pg_fetch_result($result,0,"title");
  19. }  
  20.  
  21. if (!conn)
  22. {
  23.     echo("cant connect :(");
  24.     exit;      
  25. }
  26. else
  27. {
  28.     if (isset($_REQUEST['task'])==false) { $_REQUEST['task']='show'; }
  29.     switch($_REQUEST['task'])
  30.     {
  31.         default:
  32.         case 'show':   
  33.             $result=pg_Exec($conn,"SELECT * FROM proxy_selection ORDER BY title");
  34.             if (!$result)
  35.             {
  36.                 echo("error load records");
  37.                 exit;
  38.             } ?>
  39.             <html>
  40.             <head>
  41.             <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  42.             <style>
  43.                 th,td { padding-left:20px; }
  44.             </style>
  45.             </script>
  46.             </head>
  47.             <body>
  48.             <table cellspacing="0" cellpadding="0">
  49.                 <tr style="background-color:#CCC;">
  50.                     <td>#</td>
  51.                     <td><b>Title</b></td>
  52.                     <td><b>SQL</b></td>
  53.                     <td><b>Save</b></td>
  54.                     <td><b>Description</b></td>
  55.                     <td><b>Delete</b></td>
  56.                 </tr><?php
  57.                 $n=pg_num_rows($result);
  58.                 for($i=0;$i<$n;$i++)
  59.                 {
  60.                     $data=pg_fetch_object($result,$i); ?>
  61.                     <tr>
  62.                         <form action="proxy_selection.php?task=save" method="post">
  63.                         <td><?php echo($i); ?></td>
  64.                         <td><input type="text" name="title" value="<?php echo($data->title); ?>" /></td>
  65.                         <td><input type="text" name="sql" value="<?php echo($data->sql); ?>" /></td>
  66.                         <td><input type="submit" value="Save" /></td>
  67.                         <td><a href="proxy_selection.php?task=desc_edit&id=<?php echo($data->id); ?>"></td>
  68.                         <td><a href="proxy_selection.php?task=delete&id=<?php echo($data->id); ?>"></td>
  69.                         <?php echo($data->description); ?></a></td>
  70.                         </form>
  71.                     </tr><?php
  72.                 } ?>
  73.                 </table>
  74.                 <h2><a href="proxy_selection.php?task=new">ADD NEW</h2>
  75.             </body></html><?php
  76.         break;
  77.                
  78.         case 'save':
  79.             $id=$_REQUEST['id'];
  80.             $title=$_REQUEST['title'];
  81.             $sql=$_REQUEST['sql'];
  82.             $sql="UPDARE proxy_selection SET title='".$title."',sql='".$sql."'  WHERE id=".$id;
  83.             pg_query($conn,$sql);
  84.             header("Location: proxy_selection.php");
  85.         break;
  86.                
  87.         case 'add':
  88.             $sql="INSERT INTO proxy_selection(title) VALUES('')";  
  89.             pg_query($conn,$sql);
  90.             header("Location: proxy_selection.php");
  91.         break;
  92.                
  93.         case 'desc_edit':
  94.             $id=$_REQUEST['id']; ?>
  95.             <h1>edit description for <?php echo(get_title($id)); ?></h1>
  96.             <form action="proxy_selection.php" method="post">
  97.                 <textarea name="description"><?php echo(get_desc($id)); ?></textarea>
  98.                 <input type="hidden" name="task" value="desc_save" />
  99.                 <input type="submit" value="Save" />
  100.             </form>
  101.         break;     
  102.  
  103.         case 'desc_save':
  104.             $id=$_REQUEST['id'];
  105.             $description=$_REQUEST['description'];
  106.             $sql="UPDARE proxy_selection SET description='".$description."' WHERE id=".$id;
  107.             pg_query($conn,$sql);
  108.             header("Location: proxy_selection.php");
  109.         break;
  110.                
  111.         case 'delete':
  112.             $id=$_REQUEST['id'];
  113.             $sql="DELETE FROM proxy_selection where id=".$id;  
  114.             pg_query($conn,$sql);
  115.             header("Location: proxy_selection.php");
  116.         break; 
  117.     } //end switch
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement