title: PHP and MySQL vote system OOP
body: <p>To begin with we're beginners to PHP, we're studying Multimedia Design and we have been assigned to make a website in plain HTML. Furthermore we also have to include some PHP (which must be object-oriented). Our idea is to call the URL from our Youtube videos in our database and each video should have a vote button attached.</p>
  
  <p>We can easily call our videos to a specific page in a div box on our website. This is our video_class.php:</p>
  
  <pre><code>&lt;?php class Video {
  private $db;    
  public function insertVideo($videoId) {
      $row = $this-&gt;db-&gt;query("SELECT url FROM video WHERE id = ".$videoId);
      $ost = $this-&gt;db-&gt;loadRows($row);
  
      echo '&lt;iframe width="200" height="200" src="https://www.youtube.com/embed/' . $ost[0]['url'] . '" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
  }
  
  public function setDatabaseConnection($db) {
      $this-&gt;db = $db;
  } } ?&gt;
  </code></pre>
  
  <p>And the page we're loading it to:</p>
  
  <pre><code>&lt;?php // Create database connection
  
  // Load Database class file
  require_once 'db_class.php'; 
  
  //Creating new object instance from Database class
  $db = new event(); 
  
  // Run initiate function and provide credentials.
  $db-&gt;initiate("localhost","root","","event"); 
  
  
  $db-&gt;connect();                 // Connect to MySQL database
  
  // Load Video class file
  require_once 'video_class.php'; 
  
  
  $video  = new Video;
  $video-&gt;setDatabaseConnection($db);
  
  $row=$db-&gt;query("SELECT url FROM video WHERE id = 1");
  $ost=$db-&gt;loadRows($row);
  //var_dump($ost);
  $row1=$db-&gt;query("SELECT url FROM video WHERE id = 2");
  $ost1=$db-&gt;loadRows($row1);
  //var_dump($ost1);
  $row2=$db-&gt;query("SELECT url FROM video WHERE id = 3");
  $ost2=$db-&gt;loadRows($row2);
  //var_dump($ost2); ?&gt;
  </code></pre>
  
  <p>HTML:
              </p>
  
  <pre><code>    &lt;center&gt;&lt;div class="video_clip"&gt;
  
  &lt;?php echo '&lt;iframe width="200" height="200" src="https://www.youtube.com/embed/' . $ost[0]['url'] . '" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;'; ?&gt;
  
          &lt;a href="events_vote.php?userid=1&amp;videoid=1"&gt;&lt;img src="images/vote.png"&gt;&lt;/a&gt;
  
          &lt;/div&gt;&lt;!--video_clip end--&gt;
  </code></pre>
  
  <p>But the real problem is next:</p>
  
  <p>We have 3 videos you can vote on by clicking on the vote button, under each video. Each button must count the clicks and store it in our database. We have absolutely no clue how to make this possible. Our teacher told to link to a subpage (for example, "vote.php"). On that page we should use:</p>
  
  <ul>
  <li>$_GET[id]</li>
  <li>fetch id from $get</li>
  <li>get current votes from video where id = 1/2/3</li>
  <li>add+1</li>
  <li>save votes in video where id=1</li>
  <li>and finish with a redirect</li>
  </ul>
  
  <p>Can someone help us? We have found a few possible solutions on the forums, but still no luck! Sorry for the long post and too much text :)</p>
  
  <p>DATABASE STRUCTURE:</p>
  
  <pre>
  Table name:
  users
  
  Table comments: users
  
  Column  Type    Null    Default Comments    MIME
  
  id  int(11) No          
  videoId int(11) No          
  
  Table name:
  video
  
  Table comments: video
  
  Column  Type    Null    Default Comments    MIME
  
  id  int(11) No          
  url varchar(50) No       
  </pre>