I have been asked to develop a Reporting System for an English Class as part of an assignment for Uni.

I have two tables

  • Students
  • English

the data going into the grading system are

  • Exam Mark
  • Exam Comment
  • Coursework Mark
  • Coursework Comment
  • Poetry
  • Creative Writing
  • English Literature
  • Overall Comments

I have a primary key in both tables called upn but how do I connect the students from the student table to the information in the English table. I am new to PHP and I am lost in this so any help would be greatly appreciated.

Recommended Answers

All 24 Replies

Have an auto-increement ID in both tables. And the one in students table should be a primary key so you will have it as a foreign key in the English table. That way you're making a connection between both tables. Otherwise, you can do vice-versa. You can use the student name(easy to follow and track) as a foreign key in the English table as well. But, This would depend on what your keys are.

I hope this helps you a bit.

Further to what rotten69 has said, you just need a field in your English table called student_id which then relates to the id primary key of the student in the Students table.

For example if the Student has an id of 1 in the Students table then when you insert the details for that student into the English table you would ensure that the records student_id is also 1.

Hi Guys,

I have been trying to get this code working all morning but I am way out of my depth. Can anyone please help???

<?php 
	 
 
function doquery($query) {
  $db = "prs";
  $link = mysql_connect("localhost",".......","........")
    or die("Could not connect to server! Error: ".mysql_error());
  mysql_select_db($db,$link)
    or die("Could not select $db! Error: ".mysql_error());
  $result = mysql_query($query,$link)
    or $result = "Query Error!<p>Query: $query<p>Error: ".mysql_error();
  mysql_close($link);
  return($result);
}

function parseresults($result) {
  if ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
     displayform($line);
  } else {
    print "A database problem has occurred. Contact the database administrator<p>";
  }
}


function displayform($line) {

print <<<HTML
<html>
<body>
  <form action="gradebook2.php" method="post">
  <H4>Thank You, <p>
HTML;
  print $line['firstname']." ".$line['surname']." (#".$line['upn'].") in set ".$line['class_set'];
  print ' has been sucessfully added to the system.<p>';
    
  echo"<form id=\"Gradebook\" name=\"gradebook\" method=\"post\" action=\"gradebook2.php\">
 	     <table width=\"77%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#de6057\">
        <tr>
          <td width=\"45%\" class=\"footer\"><label class=\"form_labels\">Coursework Mark</label></td>
          <td width=\"55%\"><input name=\"cw_mark\" type=\"text\" id=\"cw_mark\" value=".$line['english_cw_mark']." tabindex=\"1\" size=\"6\" maxlength=\"4\" /><input type=\"hidden\" name=\"upn\" value=".$line['upn']."></td>
        </tr>
        <tr>
          <td class=\"footer\">Coursework Comment </td>
          <td><label>
            <textarea name=\"cw_comment\" id=\"cw_comment\" cols=\"35\" rows=\"7\" value=".$line['english_cw_commnents']."></textarea>
          </label></td>
        </tr>
        <tr>
          <td class=\"footer\"><label class=\"form_labels\">Exam Mark</label></td>
          <td><input name=\"exam_mark\" type=\"text\" id=\"exam_mark\" value=".$line['english_exam_mark']." tabindex=\"3\" size=\"6\" maxlength=\"4\" /></td>
        </tr>
        <tr>
          <td class=\"form_labels\">Exam Comment </td>
          <td><label>
            <textarea name=\"exam_comment\" id=\"exam_comment\" cols=\"35\" rows=\"7\"value=".$line['english_exam_comments']."></textarea>
          </label></td>
        </tr>
        <tr>
          <td class=\"form_labels\"><label>Commendation in Poetry</label></td>
          <td><span class=\"form_labels\">
            <select name=\"com_poetry\" id=\"com_poetry\" value=".$line['com_poetry'].">
              <option value=\"No Commendation\" selected=\"selected\">No Commendation</option>
              <option value=\"Commendation Awarded\">Commendation Awarded</option>
</select>
          </span></td>
        </tr>
        <tr>
          <td class=\"form_labels\"><label>Commendation in Creative Writing</label></td>
          <td><span class=\"form_labels\">
            <select name=\"com_creative\" id=\"com_creative\" value=".$line['com_creative'].">
              <option selected=\"selected\">No Commendation</option>
              <option value=\"Commendation Awarded\">Commendation Awarded</option>
</select>
          </span></td>
        </tr>
        <tr>
          <td class=\"form_labels\">Commendation in Literary Interpretation</td>
          <td><select name=\"com_lit_int\" id=\"com_lit_int\" value=".$line['com_lit_int'].">
            <option value=\"No Commendation\" selected=\"selected\">No Commendation</option>
            <option value=\"Commendation Awarded\">Commendation Awarded</option>
</select></td>
        </tr>
        <tr>
          <td class=\"form_labels\"><label>Overall Comments</label></td>
          <td><textarea name=\"overall_comments\" id=\"overall_comments\" cols=\"35\" rows=\"7\" value=".$line['english_overall_commnents'].'"></textarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type=\"reset\" name=\"Reset\" id=\"Reset\" value=\"Reset Form\" tabindex=\"12\" />
          &nbsp;&nbsp;
		  <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit Form\" tabindex=\"11\" /></td>
        </tr>
      </table>
	  
 	  
    </form>";

<<<HTML
</body>
</html>
HTML;
}


$student_upn = (integer) $_POST["stu_upn"];

$query = "select count(*) as numberRecords from english where upn = ".$student_upn."";
$result = doquery($query);
$row = mysql_fetch_array($result);

if ($row['numberRecords'] == 0)  
	{
		$query = "select students.upn from students where students.upn = ".$student_upn;
		$result = doquery($query);
		$row = mysql_fetch_array($result);
		$cw_mark = $row['english_cw_mark'];
		$cw_comment = $row['english_cw_comments'];
		$exam_mark = $row['english_exam_mark'];
		$exam_comment = $row['english_exam_comments'];
		$com_poetry = $row['com_poetry'];
		$com_creative = $row['com_creative'];
		$com_lit_int = $row['com_lit_int'];
		$overall_comment = $row['english_overall_comments'];
		$insert = "insert into english (upn, english_cw_mark, english_cw_comments, english_exam_mark, english_exam_comments, com_poetry, com_creative, com_lit_int, english_overall_ comments) values (".$student_upn.",'".$cw_mark."','".$cw_comment."', '".$exam_mark.",'".$exam_comment."','".$com_poetry."','".$com_creative."','".$com_lit_int."','".$overall_comment."',0)";
		print $insert;
		doquery($insert);
	}

$query = "select students.upn as upn, firstname, surname, class_set, from customers left join english on students.upn = english.upn where students.upn = ".$student_upn.";	
$result = doquery($query);

if (is_resource($result)) {
  parseresults($result);
} else {
  print "$result<p>\n";
}

print "<a href=\"gradebook.php\"><h4>Grade Another Student</h4></a>";
	?>

Please tell us exactly what isn't working and any errors you are getting so we can help. In the meantime, this won't work

$result = mysql_query($query,$link)
    or $result = "Query Error!<p>Query: $query<p>Error: ".mysql_error();

As you haven't created your $query yet (i.e. above this line there is no query, just your database connection).

Hi simplypixie:

I am getting the following error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../gradebook1.php on line 166

What is on line 166 of gradebook1.php as it is not in the code posted above (that code only goes to line 139)?

This line is also wrong as you are ending the query by using the " before $student_upn

$query = "select students.upn from students where students.upn = ".$student_upn;

Change to

$query = "select students.upn from students where students.upn = '".$student_upn."'";

or

$query = "select students.upn from students where students.upn = {$student_upn}";

I have changed this to the 1st of your suggestions, but no change. I am still getting the same error!

Sorry to sound so stupid but I have only been working with PHP this past 2 weeks and there is little to no tutor support.

Thanks for all your help so far, it is much appreciated.

I am now getting the following error:

PHP Syntax Check: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in your code on line 111

Well, we can't see line 166 in the previous post. Did you post all the code you've got or you actually have a problem with?


Cheers,

Firstly, take a look at all of your queries, they are all formatted incorrectly and need changing as n my post above.

I can also now see many other small errors like gaps in table names and odd surrounding qutoe marks that don't match.

I would suggest you go through the code line by line to make sure it is all formatted properly and then we can see if you still have errors.

Hi All, Thanks so far for all your help! I only posted the php code and not the rest but I have added it in here now.

I am getting the following error:

( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in .../gradebook1.php on line 83
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pupil Record System</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.oneColElsCtrHdr #container #mainContent #form1 p label {
	text-align: left;
}
td {
	text-align: left;
}
.oneColElsCtrHdr #container #mainContent #Add_Student table {
	text-align: left;
}
-->
</style>
</head>

<body class="oneColElsCtrHdr">

<div id="container">
  <div id="header">
       <img src="images/crs.png" width="276" height="100" alt="CRS" />

  
    <!-- Date & Time -->
    <div class="time">
      <?php
        $mydate = date("D j F, Y - H:i:s");
		print "<br><h4>".$mydate."</h4>";        
      ?>
    </div><!-- end Date & Time .time -->
	
  <!-- end #header --></div>
  <div id="mainContent">
  
  <!-- Top Menu -->

 	<ul>
    	<a href="index.php" class="myButton">Home</a>
 		<a href="add_student.php" class="myButton">Add Student</a>
    	<a href="del_student.php" class="myButton">Delete Student</a>
    	<a href="gradebook.php" class="myButton">Gradebook</a>
	    <a href="update_record.php" class="myButton">Update Record</a>
    	<a href="student_report.php" class="myButton">Student Report</a>
    </ul>
    

  <!-- End Top Menu -->
    <h2>Gradebook</h2>
    
<?php 
	function doquery($query) {
 	$db = "prs";
  	$link = mysql_connect("localhost","gandalf","bella")
    	or die("Could not connect to server! Error: ".mysql_error());
  	mysql_select_db($db,$link)
    	or die("Could not select $db! Error: ".mysql_error());
  	$result = mysql_query($query,$link)
    	or $result = "Query Error!<p>Query: $query<p>Error: ".mysql_error();
  	mysql_close($link);
  	return($result);
}

	function parseresults($result) {
 	 if ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
     displayform($line);
 	 } else {
   	 print "A database problem has occurred. Contact the database administrator<p>";
  }
}


function displayform($line) {
	print <<<HTML
		 <form action="gradebook2.php" method="post">
  		<H4>Thank You,
	<<<HTML; 
 	 print .$line['firstname']."".$line['surname']." (#".$line['upn'].") in set ".$line['class_set'].;
 	 print ' has been sucessfully added to the system.</h4>';
}
	
	echo " <form id=\"Gradebook\" name=\"gradebook\" method=\"post\" action=\"gradebook2.php\">
 	     	<table width=\"77%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#de6057\">
       			 <tr>
         			 <td width=\"45%\" class=\"footer\">
					 	<label class=\"form_labels\">Coursework Mark</label></td>
         			 
					 <td width=\"55%\">
					 	<input name=\"cw_mark\" type=\"text\" id=\"cw_mark\" value=".$line['english_cw_mark']." size=\"6\" maxlength=\"4\" />
						<input type=\"hidden\" name=\"upn\" value=".$line['upn'].">
					 </td>
        		</tr>
        		
				<tr>
          			<td class=\"footer\">Coursework Comment </td>
         			 <td>
					 	<label>
					 		<textarea name=\"cw_comment\" id=\"cw_comment\" cols=\"35\" rows=\"7\" value=".$line['english_cw_commnents']."></textarea>
       					</label>
					</td>
       			</tr>
        
				<tr>
         			 <td class=\"footer\"><label class=\"form_labels\">Exam Mark</label></td>
         			 <td>
					 	<input name=\"exam_mark\" type=\"text\" id=\"exam_mark\" value=".$line['english_exam_mark']." size=\"6\" maxlength=\"4\">
					</td>
        		</tr>
       
	   			<tr>
          			<td class=\"form_labels\">Exam Comment </td>
          			<td>	
						<label>
            				<textarea name=\"exam_comment\" id=\"exam_comment\" cols=\"35\" rows=\"7\" value=".$line['english_exam_comments']."></textarea>
          				</label>
					</td>
        		</tr>
       
	   			<tr>
          			<td class=\"form_labels\"><label>Commendation in Poetry</label></td>
         			 <td>
					 	<select name=\"com_poetry\" id=\"com_poetry\" value=".$line['com_poetry'].">
              				<option value=\"No Commendation\" selected=\"selected\">No Commendation</option>
			             	<option value=\"Commendation Awarded\">Commendation Awarded</option>
						</select>
					</td>
		       </tr>
        
			   <tr>
		          <td class=\"form_labels\"><label>Commendation in Creative Writing</label></td>
        		  <td>
				  	<select name=\"com_creative\" id=\"com_creative\" value=".$line['com_creative'].">
              			<option selected=\"selected\">No Commendation</option>
             			<option value=\"Commendation Awarded\">Commendation Awarded</option>
					</select>
         		  </td>
        		</tr>
        
				<tr>
          			<td class=\"form_labels\">Commendation in Literary Interpretation</td>
         			 <td>
					 	<select name=\"com_lit_int\" id=\"com_lit_int\" value=".$line['com_lit_int'].">
            				<option value=\"No Commendation\" selected=\"selected\">No Commendation</option>
           					<option value=\"Commendation Awarded\">Commendation Awarded</option>
						</select>
					</td>
        		</tr>
        
				<tr>
		         	 <td class=\"form_labels\"><label>Overall Comments</label></td>
        		  	 <td>
				  		<textarea name=\"overall_comments\" id=\"overall_comments\" cols=\"35\" rows=\"7\" value=".$line['english_overall_commnents'].'"></textarea>
				 	 </td>
        		</tr>
       
	   			<tr>
          			<td>&nbsp;</td>
          			<td>
						<input type=\"reset\" name=\"Reset\" id=\"Reset\" value=\"Reset Form\" /> &nbsp;&nbsp;
			  			<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Submit Form\" />
					</td>
        		</tr>
      		</table>
	  </form>";
}

$student_upn = (integer) $_POST["stu_upn"];
$query = "select count(*) as numberRecords from english where upn = ".$student_upn."";
$result = doquery($query);
$row = mysql_fetch_array($result);

if ($row['numberRecords'] == 0)  
	{
		$query = "select students.upn from students where students.upn = '".$student_upn."'";
		$result = doquery($query);
		$row = mysql_fetch_array($result);
		$cw_mark = $row['english_cw_mark'];
		$cw_comment = $row['english_cw_comments'];
		$exam_mark = $row['english_exam_mark'];
		$exam_comment = $row['english_exam_comments'];
		$com_poetry = $row['com_poetry'];
		$com_creative = $row['com_creative'];
		$com_lit_int = $row['com_lit_int'];
		$overall_comment = $row['english_overall_comments'];
		$insert = "insert into english (upn, english_cw_mark, english_cw_comments, english_exam_mark, english_exam_comments, com_poetry, com_creative, com_lit_int, english_overall_ comments) values (".$student_upn.",'".$cw_mark."','".$cw_comment."', '".$exam_mark.",'".$exam_comment."','".$com_poetry."','".$com_creative."','".$com_lit_int."','".$overall_comment."',0);
		print $insert;
		doquery($insert);
	}

		$query =  select students.upn as upn, firstname, surname, class_set, from customers left join english on students.upn = english.upn where students.upn = ".$student_upn.";	
		$result = doquery($query);

		if (is_resource($result)) {
 			parseresults($result);
		} else {
  			print "$result";
		}
		print "<a href=\"gradebook.php\"><h4>Grade Another Student</h4></a>";
?>
    <!-- end #mainContent -->
  </div>
   <!-- Footer -->
  <div id="footer">
    <p class="footer">
 	 	<a href="index.php" class="footer">Home</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="add_student.php" class="footer">Add Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	    <a href="del_student.php" class="footer">Delete Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="gradebook.php" class="footer">Gradebook</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	    <a href="update_record.php" class="footer">Update Record</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="student_report.php" class="footer">Student Report</a>
    </p>
  <!-- end Footer #footer --></div></div>
<!-- end #container --></div>
</body>
</html>

The errors you describe are all caused because you messed up the ; and quotes. I spotted one when I was looking through it:

Line 195 >> The query must be encapsed in quotes, e.g. $query = "SELECT * FROM my_table WHERE a_column='".$search_string."'"; So when your code stops giving errors such as 'missing ; statement' or 'unexpected T_STRING', your syntax is incorrect :)

~G

Hi Graphix,

Thanks for the help, but I am that lost now, to be honest I don't think I can fix this.

I am not sure if this will be exactly how you want things to work but I have tidied and corrected everything so that hopefully you can at least work with the file more easily and understand what was wrong in your original code (I have removed the printing of the HTML as just becomes confusing):

<?php 

function doquery($query) {
 	$db = "prs";
  	$link = mysql_connect("localhost","gandalf","bella")
    	or die("Could not connect to server! Error: ".mysql_error());
  	mysql_select_db($db,$link)
    	or die("Could not select $db! Error: ".mysql_error());
  	$result = mysql_query($query,$link)
    	or $result = "Query Error!<p>Query: $query<p>Error: ".mysql_error();
  	return($result);
  	mysql_close($link);
}

if isset($_POST['submit']) {

$success=0;

$student_upn = mysql_real_escape_string($_POST["stu_upn"]);
$query = "select count(*) as numberRecords from english where upn = '".$student_upn."'";
$result = doquery($query);
$row = mysql_fetch_array($result);

if ($row['numberRecords'] == 0)  
	{
		$query = "select upn from students where upn = '".$student_upn."'";
		$result = doquery($query);
		$row = mysql_fetch_array($result);
		$cw_mark = $row['english_cw_mark'];
		$cw_comment = $row['english_cw_comments'];
		$exam_mark = $row['english_exam_mark'];
		$exam_comment = $row['english_exam_comments'];
		$com_poetry = $row['com_poetry'];
		$com_creative = $row['com_creative'];
		$com_lit_int = $row['com_lit_int'];
		$overall_comment = $row['english_overall_comments'];
		$insert = "insert into english (upn, english_cw_mark, english_cw_comments, english_exam_mark, english_exam_comments, com_poetry, com_creative, com_lit_int, english_overall_ comments) values ('".$student_upn."','".$cw_mark."','".$cw_comment."', '".$exam_mark.",'".$exam_comment."','".$com_poetry."','".$com_creative."','".$com_lit_int."','".$overall_comment."')";
		doquery($insert);
	}

		$query =  "select * from students where upn = '".$student_upn."'";	
		$result = doquery($query);
		if ($result) {
			$success=1;
		}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pupil Record System</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.oneColElsCtrHdr #container #mainContent #form1 p label {
	text-align: left;
}
td {
	text-align: left;
}
.oneColElsCtrHdr #container #mainContent #Add_Student table {
	text-align: left;
}
-->
</style>
</head>

<body class="oneColElsCtrHdr">

<div id="container">
  <div id="header">
       <img src="images/crs.png" width="276" height="100" alt="CRS" />

  
    <!-- Date & Time -->
    <div class="time">
      <?php
        $mydate = date("D j F, Y - H:i:s");
		print "<br><h4>".$mydate."</h4>";        
      ?>
    </div><!-- end Date & Time .time -->
	
  <!-- end #header --></div>
  <div id="mainContent">
  
  <!-- Top Menu -->

 	<ul>
    	<a href="index.php" class="myButton">Home</a>
 		<a href="add_student.php" class="myButton">Add Student</a>
    	<a href="del_student.php" class="myButton">Delete Student</a>
    	<a href="gradebook.php" class="myButton">Gradebook</a>
	    <a href="update_record.php" class="myButton">Update Record</a>
    	<a href="student_report.php" class="myButton">Student Report</a>
    </ul>
    

  <!-- End Top Menu -->
    <h2>Gradebook</h2>
<?php if ($success==1) { ?>
	<h4>Thank You, <?php echo $line['firstname']." ".$line['surname']." (#".$line['upn'].") in set ".$line['class_set']; ?>
has been sucessfully added to the system.</h4>
<?php } ?>    

		 <form action="gradebook2.php" method="post">
	
	<form id="Gradebook" name="gradebook" method="post" action="gradebook2.php">
 	     	<table width="77%" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#de6057">
       			 <tr>
         			 <td width="45%" class="footer">
					 	<label class="form_labels">Coursework Mark</label></td>
         			 
					 <td width="55%">
					 	<input name="cw_mark" type="text" id="cw_mark" value="<?php echo $line['english_cw_mark']; ?>" size="6" maxlength="4" />
						<input type="hidden" name="upn" value="<?php echo $line['upn']; ?>">
					 </td>
        		</tr>
        		
				<tr>
          			<td class="footer">Coursework Comment </td>
         			 <td>
					 	<label>
					 		<textarea name="cw_comment" id="cw_comment" cols="35" rows="7" value="<?php echo $line['english_cw_commnents']; ?>"></textarea>
       					</label>
					</td>
       			</tr>
        
				<tr>
         			 <td class="footer"><label class="form_labels">Exam Mark</label></td>
         			 <td>
					 	<input name="exam_mark" type="text" id="exam_mark" value="<?php echo $line['english_exam_mark']; ?>" size="6" maxlength="4">
					</td>
        		</tr>
       
	   			<tr>
          			<td class="form_labels">Exam Comment </td>
          			<td>	
						<label>
            				<textarea name="exam_comment" id="exam_comment" cols="35" rows="7" value="<?php echo $line['english_exam_comments']; ?>"></textarea>
          				</label>
					</td>
        		</tr>
       
	   			<tr>
          			<td class="form_labels"><label>Commendation in Poetry</label></td>
         			 <td>
					 	<select name="com_poetry" id="com_poetry" value="<?php echo $line['com_poetry']; ?>">
              				<option value="No Commendation" selected="selected">No Commendation</option>
			             	<option value="Commendation Awarded">Commendation Awarded</option>
						</select>
					</td>
		       </tr>
        
			   <tr>
		          <td class="form_labels"><label>Commendation in Creative Writing</label></td>
        		  <td>
				  	<select name="com_creative" id="com_creative" value="<?php echo $line['com_creative']; ?>">
              			<option selected="selected">No Commendation</option>
             			<option value="Commendation Awarded">Commendation Awarded</option>
					</select>
         		  </td>
        		</tr>
        
				<tr>
          			<td class="form_labels">Commendation in Literary Interpretation</td>
         			 <td>
					 	<select name="com_lit_int" id="com_lit_int" value="<?php echo $line['com_lit_int']; ?>">
            				<option value="No Commendation" selected="selected">No Commendation</option>
           					<option value="Commendation Awarded">Commendation Awarded</option>
						</select>
					</td>
        		</tr>
        
				<tr>
		         	 <td class="form_labels"><label>Overall Comments</label></td>
        		  	 <td>
				  		<textarea name="overall_comments" id="overall_comments" cols="35" rows="7" value="<?php echo $line['english_overall_commnents']; ?>"></textarea>
				 	 </td>
        		</tr>
       
	   			<tr>
          			<td>&nbsp;</td>
          			<td>
						<input type="reset" name="Reset" id="Reset" value="Reset Form" /> &nbsp;&nbsp;
			  			<input type="submit" name="submit" id="submit" value="Submit Form" />
					</td>
        		</tr>
      		</table>
	  </form>

		<h4><a href="gradebook.php">Grade Another Student</a></h4>

    <!-- end #mainContent -->
  </div>
   <!-- Footer -->
  <div id="footer">
    <p class="footer">
 	 	<a href="index.php" class="footer">Home</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="add_student.php" class="footer">Add Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	    <a href="del_student.php" class="footer">Delete Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="gradebook.php" class="footer">Gradebook</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	    <a href="update_record.php" class="footer">Update Record</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    	<a href="student_report.php" class="footer">Student Report</a>
    </p>
  <!-- end Footer #footer --></div></div>
<!-- end #container --></div>
</body>
</html>

To be honest there are a few unnecessary queries in my opinion but I will leave it with you to see if you can simplify things once you have got the code working as is.

Hi Simplypixie,

Thank you so so much, I have replaced my old code with your new code but I am now getting an error on line 15.

Error Message:

( ! ) Parse error: syntax error, unexpected T_ISSET, expecting '(' in C:\wamp\www\prs_assign\gradebook1.php on line 15

Line 15

if isset($_POST['submit']) {

Will I need to change anything in my previous php page 'gradebook.php' for this to work.

Gradebook.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fergal McCann - B00381883 - Pupil Record System</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.oneColElsCtrHdr #container #mainContent #form1 p label {
    text-align: left;
}
td {
    text-align: left;
}
.oneColElsCtrHdr #container #mainContent #Add_Student table {
    text-align: left;
}
-->
</style>
</head>

<body class="oneColElsCtrHdr">

<div id="container">
  <div id="header">
       <img src="images/crs.png" width="276" height="100" alt="CRS" />


    <!-- Date & Time -->
    <div class="time">
      <?php
        $mydate = date("D j F, Y - H:i:s");
        print "<br><h4>".$mydate."</h4>";        
      ?>
    </div><!-- end Date & Time .time -->

  <!-- end #header --></div>
  <div id="mainContent">

  <!-- Top Menu -->

    <ul>
        <a href="index.php" class="myButton">Home</a>
        <a href="add_student.php" class="myButton">Add Student</a>
        <a href="del_student.php" class="myButton">Delete Student</a>
        <a href="gradebook.php" class="myButton">Gradebook</a>
        <a href="update_record.php" class="myButton">Update Record</a>
        <a href="student_report.php" class="myButton">Student Report</a>
    </ul>


  <!-- End Top Menu -->
    <h2>Update Student Record</h2>

    <?php 
     $db="prs";
     $link=mysql_connect("localhost","gandalf","bella") or die("Cannot Connect to the database!");

     mysql_select_db($db,$link) or die ("Cannot select the database!");
     $query="SELECT * FROM students";

          $resource=mysql_query($query,$link);
          echo "
        <table align=\"center\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#de5f57\" width=\"80%\">
        <tr>
            <td><h4>First Name</h4></td>
            <td><h4>Surname</h4></td>
            <td><h4>Address</h4></td>
            <td><h4>Phone</h4></td>
            <td><h4>Class</h4></td>
            <td><h4>Grade</h4></td>

        </tr> ";
while($result=mysql_fetch_array($resource))
    { 
    echo "<tr class=\"table_data\"><td>".$result[2]."</td><td>".$result[1]."</td><td>".$result[3]."</td><td>".$result[8]."</td><td>".$result[10]."</td><td>


    <a href=\"gradebook1.php?id={$result[0]}&firstname={$result[2]}&surname={$result[1]}&class_set={$result[10]}\"><img border=\"0\" src=\"images/gradebook.png\" onmouseover=\"this.src='images/gradebook_over.png';\" onmouseout=\"this.src='images/gradebook.png';\" /></a>
    </td></tr>";
    } echo "</table>";
     ?>
      </br>
    <!-- end #mainContent -->
  </div>
   <!-- Footer -->
  <div id="footer">
    <p class="footer">
        <a href="index.php" class="footer">Home</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <a href="add_student.php" class="footer">Add Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <a href="del_student.php" class="footer">Delete Student</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <a href="gradebook.php" class="footer">Gradebook</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <a href="update_record.php" class="footer">Update Record</a> &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <a href="student_report.php" class="footer">Student Report</a>
    </p>
  <!-- end Footer #footer --></div></div>
<!-- end #container --></div>
</body>
</html>

Sorry, I missed opening and closing brackets (these are the sorts of things you need to look out for when you get errors in your code). It should be:

if (isset($_POST['submit'])) {

if you look at the code-coloring you see that most of your code is one big echo statment strarting on line 87
if you have such a large part of plain HTML it's better to go outof php
if you than have to echo a variable just put the stament between <?php ?>

print ' has been sucessfully added to the system.<p>';
 ?>
<form id="Gradebook" name="gradebook" method="post" action="gradebook2.php">
....
<input name="cw_mark" type="text" id="cw_mark" value="<?php echo $line['english_cw_mark']; ?>" 
more html here

Hi Guys,

I scrapped the old script and I have tried to do this in a different way, but I am still running in to problems.

I have posted the new code below.

<?php 
	 $id=$_REQUEST['id']; 
	 $firstname=$_REQUEST['firstname'];
	 $surname=$_REQUEST['surname'];
	 $db='prs';
	 
	 $link=mysql_connect("localhost",".......",".....") or die("Cannot Connect to the database!");
	
	 mysql_select_db($db,$link) or die ("Cannot select the database!");
	 
	 $query="SELECT * FROM english INNER JOIN students ON english.upn = students.upn";
		
		 $resource=mysql_query($query,$link) or die ("An unexpected error occured while trying to <b>access</b> this record, Please try again!");
		  $result=mysql_fetch_array($resource);
		  
	 ?>
     
    <form id="Gradebook" name="gradebook" method="post" action="gradebook2.php">
    <table width="77%" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#de6057">
    <tr>
    <td width="45%" class="footer">
        <input type="hidden" name="upn" value="<?php echo $result[0] ?>">
    <label class="form_labels">Coursework Mark</label></td>

     
    <td width="55%">
    <input name="cw_mark" type="text" id="cw_mark" value="<?php echo $result[1] ?>" size="6" maxlength="4" />
    </td>
    </tr>
     
    <tr>
    <td class="footer">Coursework Comment </td>
    <td>
    <label>
    <textarea name="cw_comment" id="cw_comment" cols="35" rows="7" value="<?php echo $result[2] ?>"></textarea>
    </label>
    </td>
    </tr>
     
    <tr>
    <td class="footer"><label class="form_labels">Exam Mark</label></td>
    <td>
    <input name="exam_mark" type="text" id="exam_mark" value="<?php echo $result[3] ?>" size="6" maxlength="4">
    </td>
    </tr>
     
    <tr>
    <td class="form_labels">Exam Comment </td>
    <td>
    <label>
    <textarea name="exam_comment" id="exam_comment" cols="35" rows="7" value="<?php echo $result[4] ?>"></textarea>
    </label>
    </td>
    </tr>
     
    <tr>
    <td class="form_labels"><label>Commendation in Poetry</label></td>
    <td>
    <select name="com_poetry" id="com_poetry" value="<?php echo $result[5] ?>">
    <option value="No Commendation" selected="selected">No Commendation</option>
    <option value="Commendation Awarded">Commendation Awarded</option>
    </select>
    </td>
    </tr>
     
    <tr>
    <td class="form_labels"><label>Commendation in Creative Writing</label></td>
    <td>
    <select name="com_creative" id="com_creative" value="<?php echo $result[6] ?>">
    <option selected="selected">No Commendation</option>
    <option value="Commendation Awarded">Commendation Awarded</option>
    </select>
    </td>
    </tr>
     
    <tr>
    <td class="form_labels">Commendation in Literary Interpretation</td>
    <td>
    <select name="com_lit_int" id="com_lit_int" value="<?php echo $result[7] ?>">
    <option value="No Commendation" selected="selected">No Commendation</option>
    <option value="Commendation Awarded">Commendation Awarded</option>
    </select>
    </td>
    </tr>
     
    <tr>
    <td class="form_labels"><label>Overall Comments</label></td>
    <td>
    <textarea name="overall_comments" id="overall_comments" cols="35" rows="7" value="<?php echo $result[8] ?>"></textarea>
    </td>
    </tr>
     
    <tr>
    <td>&nbsp;</td>
    <td>
    <input type="reset" name="Reset" id="Reset" value="Reset Form" /> &nbsp;&nbsp;
    <input type="submit" name="submit" id="submit" value="Submit Form" />
    </td>
    </tr>
    </table>
    </form>

You haven't said exactly what problems you are having

What I had hope to do was the following:

  • when I access the gradebook.php page I am presented with a list of student data. (see fig1)
  • When I click on the grade icon in the far right hand column I am then directed to gradebook1.php (see fig 2)
  • When I access gradebook1, the idea was that if there was already information in there then I could update the current information and if there was no information then I could add the information.

I hope this makes sense.

OK, I now know what you want to do but what problem are you having (i.e. what isn't working how you need it to)?

I am not sure what part of the code isn't working but the fields from the database table 'english' are not being populated into the form.

OK, try echoing them with their field names, not array numbers, for example

<?php echo $result['upn']; ?>

If that doesn't work then run your query in PHPMyAdmin to make sure it is actually working and selecting results as expected

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.