title: Inserting data in one table which has two foreign keys (php)
body: <p>I'm new to this site, and I need some help with my record system. I need to insert the grades of the students into the <strong>grades</strong> table, which has the columns: <em>gradeid</em> (PK, auto_increment), <em>studentid</em> (FK), <em>courseid</em> (FK), <em>midterm</em>, <em>endterm</em>, <em>final</em>, <em>remark</em>. </p>
  
  <p>The <em>studentid</em> (FK) gets the number from the studentid (PK) of <strong>addrec</strong> table.</p>
  
  <p>The <em>courseid</em> (FK) gets the number from the courseid (PK) of <strong>course</strong> table.</p>
  
  <p>Here are the codes that I have experimented (for the umpteenth time) but still got no results:</p>
  
  <pre><code>&lt;?php
  $host="localhost";  
  $username="root"; 
  $password=""; 
  $db_name="studentrec";
  
  
  $studentid = $_GET['id'];
  $sql1="SELECT studentid FROM addrec WHERE studentid='$studentid'";
  
  if(mysql_query($sql1))
  {
  $courseid = $_GET['courseid'];
  $sql2 = "SELECT courseid FROM course WHERE courseid='$courseid'";
  
  if (mysql_query ($sql2)) 
  {
  $sql3="INSERT INTO grades(`studentid`, `courseid`, `midterm`, `endterm`, `final`,    remark`) VALUES   ('$studentid','$courseid','$_POST[midterm]','$_POST[endterm]','$_POST[final]','$_POST[remark]' )";
  }
  if (mysql_query($sql3))
  {
      // Success
  }
  else 
  {
      die('Error on query 2: ' . mysql_error($con));
  }
  }
  ?&gt;
  </code></pre>
  
  <p>There are no errors whenever I hit the Submit button, but the data I put in the text boxes won't insert into the <strong>grades</strong> table. Help, please? Or suggestions? I'm still studying stuff about PHP. Thank you. :)</p>