Advertisement
Guest User

class-fav

a guest
Mar 8th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. require_once('dbconfig.php');
  3.  
  4. class favorite {
  5.  
  6. public $servername;
  7. public $username;
  8. public $password;
  9. public $db_name;
  10.  
  11. public function __construct(){
  12. $this->servername = "localhost";
  13. $this->db_name = "my_cdefrancesco";
  14. $this->username = "";
  15. $this->password = "";
  16.  
  17. }
  18.  
  19. public function runQuery($sql){
  20. $stmt = $this->conn->prepare($sql);
  21. return $stmt;
  22. }
  23.  
  24. public function insertFavorite($user_id, $artwork_id){
  25. $conn = new mysqli($this->servername, $this->username, $this->password, $this->db_name);
  26. if ($conn->connect_error) {
  27. print ('si è verificato un errore, si prega di riprovare');
  28. die("Connection failed: " . $conn->connect_error);
  29. }
  30. $sql = "INSERT INTO ivisits (user_id, artwork_id) VALUES ($user_id, '$artwork_id')";
  31.  
  32. if ($conn->query($sql) === TRUE) {
  33. //echo "New record created successfully";
  34. $message = "opera aggiunta con successo";
  35. print ($message);
  36. } else {
  37. echo "si è verificato un errore, si prega di riprovare";
  38. //echo "Error: " . $sql . "<br>" . $conn->error;
  39. }
  40. $conn->close();
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement