Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Tabela {
- public $sitename = "Prvi zadatak";
- private $host = 'localhost';
- private $user = 'root';
- private $password = '';
- private $database = 'vphp';
- public $connection;
- public function connection() {
- $this->connection = new mysqli ( $this->host, $this->user, $this->password, $this->database );
- if ($this->connection->connect_error) {
- $this->error ( $this->connection->connect_error );
- }
- }
- public function prikazi() {
- $this->connection ();
- $conn = $this->connection;
- // var_dump($conn);
- $sql = "SELECT * FROM news";
- // echo $sql;
- $result = $conn->query ( $sql );
- $data = array ();
- if ($result->num_rows > 0) {
- // output data of each row
- WHILE ( $row = $result->fetch_assoc () ) {
- $data [] = $row;
- }
- }
- return $data;
- }
- public function dodaj() {
- $this->connection ();
- $conn = $this->connection;
- if (isset ( $_POST ['title_input'] ) and $_POST ['title_input'] != "") {
- $title = $_POST ['title_input'];
- $content = mysqli_real_escape_string ( $conn, $_POST ['content_input'] );
- if ($mode = "add")
- $sql = "INSERT INTO news (title, content) VALUES ('$title', '$content')";
- else if ($mode = "edit")
- $sql = "UPDATE news Title='$title', Content = '$content'";
- $result = mysqli_query ( $conn, $sql );
- if (mysqli_error ( $conn )) {
- echo "zajebo si nešto";
- } else {
- echo "ma bravo bre";
- }
- }
- if ($mode == "edit") {
- $sql = "SELECT * FROM news WHERE id = '$id'";
- $result = mysqli_query ( $conn, $sql );
- $student = mysqli_fetch_array ( $result );
- }
- }
- public function brisi($id) {
- $this->connection ();
- $conn = $this->connection;
- // var_dump($conn);
- $sql = "DELETE FROM news WHERE id='$id'";
- // echo $sql;
- $conn->query ( $sql );
- }
- }
Add Comment
Please, Sign In to add comment