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 $upval and $aday are inserted correctly but $course and $chour are inserted as zeros, notice that I echo the ($course and $chour) before the insert query and the echo prints the correct values(not zero).
$res1=mysql_fetch_object($result1);
$course =$res1->cid;
$result2= mysql_query("select thoure from $tbl_name3 where cid='$course'");
$res2=mysql_fetch_object($result2);
$chour =$res2->thoure;
$sql ="insert into $tbl_name2 (SID,Cid,Tid,Adate,Ahoure) values ('$upval','$course','2','$aday','$chour')";
$result = mysql_query($sql);
also I try another way to write query but the same problem
$sql ="insert into $tbl_name2 (SID,Cid,Tid,Adate,Ahoure) values ('$upval','".$res1->cid."','2','$aday','".$res2->thoure."')";
$sqlafter you have put in the variables. The answer would then (probably) be obvious.$courseand$chournumbers or strings? Are the corresponding table columns equipped to handle the data you're inserting? If you try to enter astringinto anintfield, it will go in as 0