Jump to content

variable problem


mishuk

Recommended Posts

I have a page that relies on two variables being passed into it for the year and the school in question.  A user can then select a child from the list (list of children in school specified by variable) and enter their details.  My problem is that when my check script throws back the page either due to field not selected or data inputted I get an error

 

$school = ($_POST['school']);
$year = ($_POST['year']);

if($logged_in){
?>
<FORM action = "admin.php?do=addy9" method = "post">
<table ALIGN="center" border="0" cellspacing="2">
<tr>
<td colspan="2" bgcolor="#FFFFFF" align="center"><h1>Add Year 9 Feedback Form</h1></td>
</tr>
<TR>
<TD colspan="2" bgcolor="#FFFF00"><?
if (isset($message))
echo "<b>$message<br><br></b>";
?></TD>
</TR>
<tr>
<td>Please select a student from the list:</td>
   <td> <? $res=mysql_query("select stud_id, surname, forename from tbl_student where school_id = $school AND year = $year");

 if(mysql_num_rows($res)==0)
{
echo "No Data";
            }
 else
{
echo '<select name="student">';
echo '<option value = "-1">Select:</option>';
    while($row=mysql_fetch_assoc($res))
	{
	echo '<option value="' . $row['stud_id'] . '">' . $row['surname'] .' '. $row      ['forename'] . '</option>';
	}
	echo '</select>';
	};
?>

      <input type="hidden" name="year" value = <? echo $year; ?> />
</td>
</tr>
</table>
<br>
// form continues

// Check script, checks validity of form being submitted.
case "addy9":
if (!$_POST['student'] || $_POST['student'] == "-1") {
	unset ($_GET['do']);
	$message = "Please select a student";
	include("addy9.php");
}
else {

   	//assign variables to $_POST
   	$stud = ($_POST['student']);
   	$year = ($_POST['year']);
$q1 = ($_POST['q1']);
$q2a = ($_POST['q2a']);
   	$q2b = ($_POST['q2b']);
   	$q3 = ($_POST['q3']);
   	$q4 = ($_POST['q4']);
$q5a = ($_POST['q5a']);
$q5b = ($_POST['q5b']);

// insert data into tbl_student
$addy9feedback = "INSERT INTO tbl_y9 (stud_id, year, q1, q2a, q2b, q3, q4, q5a, q5b)
    		       VALUES ('$stud', '$year', '$q1', '$q2a', '$q2b', '$q3', '$q4', '$q5a', '$q5b')";

    $result = mysql_query($addy9feedback) or die(mysql_error());

    if (mysql_affected_rows() == 1)	{
		$message = "Entry added.";
		include("addy9.php");
	}
	else {
	error_log(mysql_error());
	$message = "Error: please try again.  If the error continues to occur containt the system administrator";
		include("addy9.php");
	}
  }
break;

 

So when the include is called the variables school and year are no longer populated.

How can i solve this.  thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.