title: Joomla plugin database mistakes? What is wrong here?
body: <p>i've just started learning Jplugin development, so here i made a little voting script. Everything here works fine, but i want conf.php file to be made in joomla framework style. As you see here, 1 and 2 files works perfectly together. I want to use third example instead of second, in which i use simple php code. The last example i tried to do is using joomla framework, but it doesnt work. I have no idea what's wrong with that code. Anyone see could tell where I made a mistake or maybe far away from doing it right ?</p>
  
  <pre><code>&lt;?php
  defined( '_JEXEC' ) or die;
  ?&gt;
  
  &lt;?php
  class plgSystemRatingx extends JPlugin
  
  {
     public function onContentBeforeDisplay()
     {
  ?&gt;
  &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function()
  {
  $(".like").click(function()
  {
  var id=$(this).attr("id");
  var name=$(this).attr("name");
  var dataString = 'id='+ id + '&amp;name='+ name;
  $("#votebox").slideDown("slow");
  
  $("#flash").fadeIn("slow");
  
  $.ajax
  ({
  type: "POST",
  url: "conf.php",
  data: dataString,
  cache: false,
  success: function(html)
  {
  $("#flash").fadeOut("slow");
  $("#content").html(html);
  } 
  });
  });
  
  $(".close").click(function()
  {
  $("#votebox").slideUp("slow");
  });
  
  });
  &lt;/script&gt;
  &lt;body&gt;
  &lt;div style="margin:50px"&gt;
  &lt;a href="#" class="like" id="1" name="up"&gt;Like&lt;/a&gt; -- &lt;a href="#" class="like" id="1" name="down"&gt;Dislike&lt;/a&gt;
  &lt;div id="votebox"&gt;
  &lt;span id='close'&gt;&lt;a href="#" class="close" title="Close This"&gt;X&lt;/a&gt;&lt;/span&gt;
  &lt;div style="height:13px"&gt;
  &lt;div id="flash"&gt;Loading........&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="content"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;?php
        return true;
     }
  }
  </code></pre>
  
  <p>this piece of code works perfectly</p>
  
  <pre><code>&lt;?php
  $mysql_hostname = "localhost";
  $mysql_user = "px";
  $mysql_password = "px";
  $mysql_database = "jum";
  $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
  or die("Opps some thing went wrong");
  mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
  
  
  if($_POST['id'])
  {
  $id=mysql_real_escape_string($_POST['id']);
  $name=mysql_real_escape_string($_POST['name']);
  
  
  mysql_query("update messages set $name=$name+1 where id='$id'");
  
  
  $result=mysql_query("select up,down from messages where id='$id'");
  $row=mysql_fetch_array($result);
  $up_value=$row['up'];
  $down_value=$row['down'];
  $total=$up_value+$down_value;
  
  $up_per=($up_value*100)/$total;
  $down_per=($down_value*100)/$total;
  ?&gt;
  &lt;div style="margin-bottom:10px"&gt;
  &lt;b&gt;Ratings for this blog&lt;/b&gt; ( &lt;?php echo $total; ?&gt; total)
  &lt;/div&gt;
  &lt;table width="700px"&gt;
  
  &lt;tr&gt;
  &lt;td width="30px"&gt;&lt;/td&gt;
  &lt;td width="60px"&gt;&lt;?php echo $up_value; ?&gt;&lt;/td&gt;
  &lt;td width="600px"&gt;&lt;div id="greebar" style="width:&lt;?php echo $up_per; ?&gt;%"&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td width="30px"&gt;&lt;/td&gt;
  &lt;td width="60px"&gt;&lt;?php echo $down_value; ?&gt;&lt;/td&gt;
  &lt;td width="600px"&gt;&lt;div id="redbar" style="width:&lt;?php echo $down_per; ?&gt;%"&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;?php
  
  }
  ?&gt;
  </code></pre>
  
  <p>and this made in joomla style doesnt work at all</p>
  
  <pre><code>&lt;?php
  defined( '_JEXEC' ) or die;
  ?&gt;
  &lt;?php
  if(JRequest::getVar('id'))
  {
  
  $id = JRequest::getInt('id');
  $name = JRequest::getInt('name');
  
  $db = JFactory::getDbo();
  
  $query = $db-&gt;getQuery(true);
  $query2 = $db-&gt;getQuery(true);
  $queryup = $db-&gt;getQuery(true);
  $querydown = $db-&gt;getQuery(true);
  
  $query-&gt;update('messages');
  $query-&gt;set("message = 1");
  $query-&gt;where("id = $id");
  
  $query2-&gt;select('up,down');
  $query2-&gt;from('messages');
  $query2-&gt;where("id = $id");
  
  
  
  $queryup-&gt;select('up');
  $queryup-&gt;from('messages');
  $queryup-&gt;where("id = $id");
  
  $querydown-&gt;select('down');
  $querydown-&gt;from('messages');
  $querydown-&gt;where("id = $id");
  
  
  $db-&gt;setQuery( $query );
  $db-&gt;query();
  $db-&gt;setQuery( $query2 );
  $db-&gt;query();
  
  $db-&gt;setQuery( $queryup );
  $data0 = $db-&gt;query();
  $db-&gt;setQuery( $querydown );
  $data1 = $db-&gt;query();
  
  
  $up_value= $db-&gt;insertid($data0);;
  $down_value = $db-&gt;insertid($data1);
  
  $total=$up_value+$down_value;
  
  $up_per=($up_value*100)/$total;
  $down_per=($down_value*100)/$total;
  
  ?&gt;
  
  &lt;table width="700px"&gt;
  
  &lt;tr&gt;
  &lt;td width="30px"&gt;&lt;/td&gt;
  &lt;td width="60px"&gt;&lt;?php echo $up_value; ?&gt;&lt;/td&gt;
  &lt;td width="600px"&gt;&lt;div id="greebar" style="width:&lt;?php echo $up_per; ?&gt;%"&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td width="30px"&gt;&lt;/td&gt;
  &lt;td width="60px"&gt;&lt;?php echo $down_value; ?&gt;&lt;/td&gt;
  &lt;td width="600px"&gt;&lt;div id="redbar" style="width:&lt;?php echo $down_per; ?&gt;%"&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;?php
  }
  </code></pre>