Jump to content
MakeWebGames

MrAshTonka

Members
  • Posts

    3
  • Joined

  • Last visited

About MrAshTonka

  • Birthday 10/05/1991

Personal Information

  • Location
    Auastralia

MrAshTonka's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thank you so much CtrlFreq its working great now :)
  2. Why would it be a line that has nothing to do with that im having trouble with ?
  3. Hello, i have a OOP login and register script and im building an admin panel for it and im trying to delete users but getting the ID from the Database and deleting them by the ID but im having some problems. here is the code im using. The problem is in the Index.php file with deleting people from the list then refreshing the list. Any help would be amazing. Index.php <?php require_once 'core/init.php'; $title = 'Shop'; $user = new User(); $select = DB::getInstance()->query("SELECT * FROM users"); $delete = DB::getInstance(); $data = $user->data(); $x=0; include_once 'temp/head.php'; if($user->isLoggedin()) { if(Session::exists('home')) { echo '<section class="success success"><p>' . Session::flash('home') . '</p></section>'; } if(isset($_POST['Delete'])) { $delete->delete('users', array('id', '=', $select->results()[$x])); } ?> <p>Hello, <?php echo escape($data->First_Name); ?>!</p> <!-- Users Name --> <p> <a href="addItem.php">Add Item</a> / <a href="logout.php">Log out</a> </p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table> <tr> <td><b>Image</b></td> <td><b>Unit Number</b></td> <td><b>QTY</b></td> <td><b>Part Number</b></td> <td><b>Descriptioin</b></td> <td><b>Net Price</b></td> <td><b>Delete</b></td> </tr> <?php foreach($select->results() as $select) { echo " <tr> <td>$select->First_Name</td> <td>$select->Last_Name</td> <td>$select->Email</td> <td>$select->Password</td> <td>$select->salt</td> <td>$select->joined</td> <td> <input type='submit' value='Delete' name='Delete'/> <input type='hidden' value='$select->id'> <input type='hidden' value='$x'> </td> </tr> "; $x++; } ?> <!-- Table list of items go here --> </table> </form> <?php }else{ ?> <table> <!-- Width: 100% --> <tr> <td><bold>Image</bold></td> <!-- Width: 10% --> <td><bold>Unit Number</bold></td> <!-- Width: 10% --> <td><bold>QTY</bold></td> <!-- Width: 10% --> <td><bold>Part Number</bold></td> <!-- Width: 10% --> <td><bold>Descriptioin</bold></td> <!-- Width: 50% --> <td><bold>Net Price</bold></td> <!-- Width: 10% --> </tr> <?php foreach($select->results() as $select) { echo " <tr> <td>$select->First_Name</td> <td>$select->Last_Name</td> <td>$select->Email</td> </tr> "; } ?> <!-- Table list of items go here --> </table> <?php } include_once 'temp/footer.php'; ?>   This is the DB Class file.   <?php class DB { private static $_instance = null; private $_pdo, $_query, $_error = false, $_results, $_count = 0; private function __construct() { try { $this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/user'), Config::get('mysql/pass')); } catch(PDOException $e) { die($e->getMessage()); } } public static function getInstance() { if(!isset(self::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } public function query($sql, $params = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($params)) { foreach($params as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); }else{ $this->_error = true; } } return $this; } public function action($action, $table, $where = array()) { if(count($where) === 3) { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; } } } return false; } public function get($table, $where) { return $this->action('SELECT *', $table, $where); } public function delete($table, $where) { return $this->action('DELETE', $table, $where); } public function insert($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO {$table} (`" . implode('`, `', $keys) . "`) VALUES ({$values})"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } public function update($table, $id, $fields) { $set = ''; $x = 1; foreach($fields as $name => $values) { $set .="{$name} = ?"; if($x < count($fields)) { $set .= ', '; } $x++; } $sql = "UPDATE {$table} SET {$set} WHERE id = {$id}"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } public function results() { return $this->_results; } public function first() { return $this->results()[0]; } public function error() { return $this->_error; } public function count() { return $this->_count; } }
×
×
  • Create New...