Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------item------------
- <?php
- require_once('database.php');
- $id = $_GET['serial'];
- $data = Database::getItem($id);
- if($data != null){
- echo $data['item_id'] . '<br />';
- echo $data['item_name'] . '<br />';
- echo $data['item_serial'] . '<br />';
- echo $data['item_number'] . '<br />';
- }
- ?>
- ------------index------------
- <form action="item.php">
- Serial Number:<br>
- <input type="text" name="serial" value="">
- <br>
- <input type="submit">
- </form>
- ------------database------------
- <?php
- class Database
- {
- private static $dbName = 'limiti';
- private static $dbHost = 'localhost';
- private static $dbUsername = 'root';
- private static $dbUserPassword = '';
- private static $cont = null;
- public function __construct() {
- die('Init function is not allowed');
- }
- public static function connect()
- {
- // One connection through whole application
- if ( null == self::$cont )
- {
- try
- {
- self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
- }
- catch(PDOException $e)
- {
- die($e->getMessage());
- }
- }
- return self::$cont;
- }
- public static function disconnect()
- {
- self::$cont = null;
- }
- public static function getItem($item_serial)
- {
- $pdo = Database::connect();
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "SELECT * FROM limited WHERE item_serial = ?";
- $q->execute(array($id));
- $data = $q->fetch(PDO::FETCH_ASSOC);
- Database::disconnect();
- //var_dump($data);
- return $data;
- }
- }
- ?>
- ------------error------------
- Notice: Undefined variable: q in C:\xampp\htdocs\database.php on line 42
- Fatal error: Call to a member function execute() on null in C:\xampp\htdocs\database.php on line 42
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement