Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. session_start();
  2. session_register('table');
  3. $qty=$_POST[txtQty];
  4. $pid=$_REQUEST[pid];
  5. $data=@mysql_query("SELECT * from products where productid=".$pid,$con) or die(mysql_error());
  6. $table=$_SESSION[table];
  7. while($row=@mysql_fetch_array($data))
  8. {
  9. $table.='<tr><td>'.$row[name].'></td>
  10. <td>'.$row[price].'</td><td>'.$qty.'</td><td>'.$row[price]*$qty.'</td>
  11. <td>Delete</td></tr>';
  12. $_SESSION[table]=$table;
  13. }
  14.  
  15. class MySQLSession
  16. {
  17. protected $resource = null;
  18. protected $db = 'base';
  19. protected $table = 'session';
  20. protected $id_col = 'sess_id';
  21. protected $data_col = 'sess_data';
  22. protected $time_col = 'sess_time';
  23.  
  24. public function __construct($context, $parameters = null){
  25. session_set_save_handler(array($this, 'sessionOpen'),
  26. array($this, 'sessionClose'),
  27. array($this, 'sessionRead'),
  28. array($this, 'sessionWrite'),
  29. array($this, 'sessionDestroy'),
  30. array($this, 'sessionGC'));
  31.  
  32. session_start();
  33. }
  34.  
  35. public function sessionClose(){
  36. return true;
  37. }
  38.  
  39. public function sessionDestroy($id){
  40. $id = mysql_real_escape_string($id, $this->resource);
  41. $sql = 'DELETE FROM '.$this->table.' WHERE '.$this->id_col.' = ''.$id.''';
  42. if (@mysql_query($sql, $this->resource)){
  43. return true;
  44. }
  45. $error = 'MySQLSessionStorage cannot destroy session id "%s"';
  46. $error = sprintf($error, $id);
  47. throw new Exception($error);
  48. }
  49.  
  50. public function sessionGC($lifetime){
  51. $sql = 'DELETE FROM '.$this->table.' '.
  52. 'WHERE '.$this->time_col.' + INTERVAL '.$lifetime.' SECOND < NOW()';
  53. if (@mysql_query($sql, $this->resource)){
  54. return true;
  55. }
  56. $error = 'MySQLSessionStorage cannot delete old sessions';
  57. throw new Exception($error);
  58. }
  59.  
  60. public function sessionOpen($path, $name){
  61. $this->resource = mysql_connect('host', 'user', 'pass', true);
  62. mysql_select_db($this->db, $this->resource);
  63. return true;
  64. }
  65.  
  66. public function sessionRead($id){
  67. $id = mysql_real_escape_string($id, $this->resource);
  68.  
  69. $sql = 'SELECT '.$this->data_col.' ' .
  70. 'FROM '.$this->table.' ' .
  71. 'WHERE '.$this->id_col.' = ''.$id.''';
  72. $result = @mysql_query($sql, $this->resource);
  73. if ($result != false && @mysql_num_rows($result) == 1){
  74. $data = mysql_fetch_row($result);
  75. return $data[0];
  76. }else{
  77. $sql = 'INSERT INTO '.$this->table.' ('.$this->id_col.', ' .
  78. $this->data_col.', '.$this->time_col.') VALUES (' .
  79. '''.$id.'', '', NOW())';
  80.  
  81. if (@mysql_query($sql, $this->resource)){
  82. return '';
  83. }
  84. $error = 'MySQLSessionStorage cannot create new record for id "%s"';
  85. $error = sprintf($error, $id);
  86. throw new Exception($error);
  87. }
  88. }
  89.  
  90. public function sessionWrite($id, &$data){
  91. $id = mysql_real_escape_string($id, $this->resource);
  92. $data = mysql_real_escape_string($data, $this->resource);
  93. $sql = 'UPDATE '.$this->table.' ' .
  94. 'SET '.$this->data_col.' = ''.$data.'', ' .
  95. $this->time_col.' = NOW() ' .
  96. 'WHERE '.$this->id_col.' = ''.$id.''';
  97.  
  98. if (@mysql_query($sql, $this->resource)){
  99. return true;
  100. }
  101. $error = 'MySQLSessionStorage cannot write session data for id "%s"';
  102. $error = sprintf($error, $id);
  103. throw new Exception($error);
  104. }
  105.  
  106. public function shutdown(){
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement