title: mysql insert query inserts zeros with some values
body: <p>I am a beginner in php and mysql and am trying to write code to insert values into a table. The problem is some variables like <code>$upval</code> and <code>$aday</code> are inserted correctly but <code>$course</code> and <code>$chour</code> are inserted as zeros, notice that I echo the (<code>$course</code> and <code>$chour</code>) before the insert query and the echo prints the correct values(not zero).</p>
  
  <pre><code>$res1=mysql_fetch_object($result1);
  $course =$res1-&gt;cid;
  $result2= mysql_query("select thoure from $tbl_name3 where cid='$course'");
  $res2=mysql_fetch_object($result2);
  $chour =$res2-&gt;thoure;
  $sql ="insert into $tbl_name2 (SID,Cid,Tid,Adate,Ahoure) values ('$upval','$course','2','$aday','$chour')";
  $result = mysql_query($sql);
  </code></pre>
  
  <p>also I try another way to write query but the same problem</p>
  
  <pre><code>$sql ="insert into $tbl_name2 (SID,Cid,Tid,Adate,Ahoure) values ('$upval','".$res1-&gt;cid."','2','$aday','".$res2-&gt;thoure."')";
  </code></pre>