Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. class DataManager {
  2. public $con;
  3. function __construct(){
  4. $this->con = mysql_connect("localhost","forum","forum");
  5. if (!$this->con) {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db("scm", $this->con);
  9. }
  10. function getIdUser($name){
  11. $name = mysql_escape_string($name);
  12. $result = mysql_query("select id from user where name like '".$name."'");
  13. $ar = array();
  14. while($row = mysql_fetch_array($result)) $ar[] = $row;
  15. return $ar[0][0];
  16. }
  17. function getNameUser($id){
  18. $id = mysql_escape_string($id);
  19. $result = mysql_query("select name from user where id=".$id);
  20. $ar = array();
  21. while($row = mysql_fetch_array($result)) $ar[] = $row;
  22. return $ar[0][0];
  23. }
  24.  
  25. function post($thid,$text){
  26. $text = mysql_escape_string($text);
  27. $text = str_replace("<","<",$text);
  28. $text = str_replace(">",">",$text);
  29. if (strlen($text)>0){
  30. $x = "insert into post(user,date,text,thread) values(".$_SESSION['user'].",NOW(),\"".$text."\",".$thid.")";
  31. if (!mysql_query($x)) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. return false;
  37. }
  38. function register($user,$pass){
  39. $user = mysql_escape_string($user);
  40. $user = str_replace("<","<",$user);
  41. $user = str_replace(">",">",$user);
  42. if (strlen($user)>0){
  43. $pass = mysql_escape_string($pass);
  44. $pass = str_replace("<","<",$pass);
  45. $pass = str_replace(">",">",$pass);
  46.  
  47. $result = mysql_query("select count(*) as c from user where name='".$user."'");
  48.  
  49. $ar = array();
  50. while($row = mysql_fetch_array($result))$ar[] = $row;
  51. if ($ar[0]['c'] != 0) return false;
  52.  
  53. $x = "insert into user(name,password) values('".$user."','".md5($user.'|'.$pass)."');";
  54. if (!mysql_query($x)) {
  55. return false;
  56. }
  57. return true;
  58. }
  59. return false;
  60. }
  61.  
  62. function newThread($name,$user){
  63. $name = mysql_escape_string($name);
  64. $name = str_replace("<","<",$name);
  65. $name = str_replace(">",">",$name);
  66. if (strlen($user)>0){
  67. $x = "insert into threads(name,creation_date,user) values('".$name."',NOW(),".$user.");";
  68. if (!mysql_query($x)) {
  69. return false;
  70. }
  71. return true;
  72. }
  73. return false;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement