daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------item------------
  2. <?php
  3. require_once('database.php');
  4. $id = $_GET['serial'];
  5.  
  6. $data = Database::getItem($id);
  7. if($data != null){
  8.   echo $data['item_id'] . '<br />';
  9.   echo $data['item_name'] . '<br />';
  10.   echo $data['item_serial'] . '<br />';
  11.   echo $data['item_number'] . '<br />';
  12. }
  13. ?>
  14.  
  15. ------------index------------
  16. <form action="item.php">
  17. Serial Number:<br>
  18. <input type="text" name="serial" value="">
  19. <br>
  20. <input type="submit">
  21. </form>
  22.  
  23. ------------database------------
  24. <?php
  25. class Database
  26. {
  27.     private static $dbName = 'limiti';
  28.     private static $dbHost = 'localhost';
  29.     private static $dbUsername = 'root';
  30.     private static $dbUserPassword = '';
  31.  
  32.     private static $cont  = null;
  33.  
  34.     public function __construct() {
  35.         die('Init function is not allowed');
  36.     }
  37.  
  38.     public static function connect()
  39.     {
  40.        // One connection through whole application
  41.        if ( null == self::$cont )
  42.        {
  43.         try
  44.         {
  45.           self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
  46.         }
  47.         catch(PDOException $e)
  48.         {
  49.           die($e->getMessage());
  50.         }
  51.        }
  52.        return self::$cont;
  53.     }
  54.  
  55.     public static function disconnect()
  56.     {
  57.         self::$cont = null;
  58.     }
  59.    
  60.     public static function getItem($item_serial)
  61.     {
  62.       $pdo = Database::connect();
  63.       $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  64.       $sql = "SELECT * FROM  limited WHERE  item_serial = ?";
  65.       $q->execute(array($id));
  66.       $data = $q->fetch(PDO::FETCH_ASSOC);
  67.       Database::disconnect();
  68.       //var_dump($data);
  69.       return $data;
  70.     }
  71.  
  72.  
  73. }
  74. ?>
  75.  
  76. ------------error------------
  77. Notice: Undefined variable: q in C:\xampp\htdocs\database.php on line 42
  78.  
  79. Fatal error: Call to a member function execute() on null in C:\xampp\htdocs\database.php on line 42
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top