Vlado_V

Tabela.php

Feb 3rd, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. class Tabela {
  3.     public $sitename = "Prvi zadatak";
  4.     private $host = 'localhost';
  5.     private $user = 'root';
  6.     private $password = '';
  7.     private $database = 'vphp';
  8.     public $connection;
  9.     public function connection() {
  10.         $this->connection = new mysqli ( $this->host, $this->user, $this->password, $this->database );
  11.         if ($this->connection->connect_error) {
  12.             $this->error ( $this->connection->connect_error );
  13.         }
  14.     }
  15.     public function prikazi() {
  16.         $this->connection ();
  17.        
  18.         $conn = $this->connection;
  19.         // var_dump($conn);
  20.         $sql = "SELECT * FROM news";
  21.         // echo $sql;
  22.         $result = $conn->query ( $sql );
  23.         $data = array ();
  24.        
  25.         if ($result->num_rows > 0) {
  26.             // output data of each row
  27.             WHILE ( $row = $result->fetch_assoc () ) {
  28.                 $data [] = $row;
  29.             }
  30.         }
  31.         return $data;
  32.     }
  33.     public function dodaj() {
  34.         $this->connection ();
  35.         $conn = $this->connection;
  36.        
  37.         if (isset ( $_POST ['title_input'] ) and $_POST ['title_input'] != "") {
  38.             $title = $_POST ['title_input'];
  39.             $content = mysqli_real_escape_string ( $conn, $_POST ['content_input'] );
  40.             if ($mode = "add")
  41.                
  42.                 $sql = "INSERT INTO news (title, content) VALUES ('$title', '$content')";
  43.             else if ($mode = "edit")
  44.                 $sql = "UPDATE news Title='$title', Content = '$content'";
  45.             $result = mysqli_query ( $conn, $sql );
  46.            
  47.             if (mysqli_error ( $conn )) {
  48.                 echo "zajebo si nešto";
  49.             } else {
  50.                 echo "ma bravo bre";
  51.             }
  52.         }
  53.         if ($mode == "edit") {
  54.             $sql = "SELECT * FROM news WHERE id = '$id'";
  55.             $result = mysqli_query ( $conn, $sql );
  56.            
  57.             $student = mysqli_fetch_array ( $result );
  58.         }
  59.     }
  60.     public function brisi($id) {
  61.         $this->connection ();
  62.        
  63.         $conn = $this->connection;
  64.         // var_dump($conn);
  65.         $sql = "DELETE FROM news WHERE id='$id'";
  66.         // echo $sql;
  67.         $conn->query ( $sql );
  68.     }
  69. }
Add Comment
Please, Sign In to add comment