Guest User

Untitled

a guest
Aug 23rd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?
  2.  
  3. function addUser($info)
  4. {
  5. $host = "localhost";
  6. $user = 'root';
  7. $pword = '';
  8. $db = 'userdb';
  9. $mycon = mysql_connect($host,$user,$pword);
  10. mysql_select_db($db,$mycon);
  11. $name = mysql_escape_string($info['name']);
  12. $age = mysql_escape_string($info['age']);
  13. $email = mysql_escape_string($info['email']);
  14. $password = mysql_escape_string($info['password']);
  15. $description = mysql_escape_string($info['description']);
  16. $query = "INSERT INTO users (name,age,email,password,description)
  17. VALUES ('$name','$age','$email','$password','$description')";
  18. if(mysql_query($query))
  19. {
  20. mysql_close($mycon);
  21. return true;
  22. }
  23. else
  24. {
  25. mysql_close($mycon);
  26. return false;
  27. }
  28. }
  29. function getUser($email,$password)
  30. {
  31. $host = "localhost";
  32. $user = 'root';
  33. $pword = '';
  34. $db = 'userdb';
  35. $mycon = mysql_connect($host,$user,$pword);
  36. mysql_select_db($db,$mycon);
  37. $query = "SELECT * FROM users WHERE email='$email' AND password='$password'";
  38. $result = mysql_query($query);
  39. $row = mysql_fetch_array($result);
  40. mysql_close($mycon);
  41. return $row;
  42. }
  43. function getUserById($id)
  44. {
  45. $host = "localhost";
  46. $user = 'root';
  47. $pword = '';
  48. $db = 'userdb';
  49. $mycon = mysql_connect($host,$user,$pword);
  50. mysql_select_db($db,$mycon);
  51. $query = "SELECT * FROM users WHERE id='$id'";
  52. $result = mysql_query($query);
  53. $row = mysql_fetch_array($result);
  54. mysql_close($mycon);
  55. return $row;
  56. }
  57. function updateUser($data)
  58. {
  59. $host = "localhost";
  60. $user = 'root';
  61. $pword = '';
  62. $db = 'userdb';
  63. $mycon = mysql_connect($host,$user,$pword);
  64. mysql_select_db($db,$mycon);
  65. $name = mysql_escape_string($data['name']);
  66. $age = mysql_escape_string($data['age']);
  67. $email = mysql_escape_string($data['email']);
  68. $tagline = mysql_escape_string($data['tagline']);
  69. $interests = mysql_escape_string($data['interests']);
  70. $description = mysql_escape_string($data['description']);
  71. $id = $_COOKIE['uid'];
  72. $query = "UPDATE users SET name='$name', age='$age', email='$email', tagline='$tagline', interests='$interests', description='$description' WHERE id='$id'";
  73. if(mysql_query($query))
  74. {
  75. mysql_close($mycon);
  76. return true;
  77. }
  78. else
  79. {
  80. mysql_close($mycon);
  81. return false;
  82. }
  83. }
  84. ?>
Add Comment
Please, Sign In to add comment