Jump to content

User error messages not working whilst passing other values through the URL


almystersv

Recommended Posts

Hi Guys,

 

I hope your all well.

 

I have this page of code that I am trying to create that wil allow the user to enter scores into the SQL database. I have inplace a series of error messages that use the pagemode function that runs the validation after the submit button is clicked. This works fine on other pages, however... on this page I am also passing the studentID through the URL (from a previous page where the user selects the student they wish to enter the scores for) this therefore crashes the page as it doesn't like me passing two values through the URL.

 

Any help would be brilliant.

Here is my code minus the html.

<?php
session_start();
if(isset($_SESSION['username']) == false){
	header("Location: login.php");
	exit();
}
require ("connect.php");

$studentID = $_GET['studentID'];	
$query = "SELECT * FROM student WHERE studentID = ".$studentID;
$result = mysql_query($query, $connection) or die ("Error: " . mysql_error());
$row= mysql_fetch_array($result);

$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';

if ($page_mode == 'newAssessment')
{
// ** POSTS THE VARIABLES BACK INTO THE TEXTBOXES **
	$Q1p1 = $_POST['Q1p1'];
	$Q1p2 = $_POST['Q1p2'];
	$Q1p3 = $_POST['Q1p3'];
	$Q1p4 = $_POST['Q1p4'];
	$Q1p5 = $_POST['Q1p5'];
	$Q2p1 = $_POST['Q2p1'];
	$Q2p2 = $_POST['Q2p2'];
	$Q2p3 = $_POST['Q2p3'];
	$Q2p4 = $_POST['Q2p4'];
	$Q2p5 = $_POST['Q2p5'];
	$Q3p1 = $_POST['Q3p1'];
	$Q3p2 = $_POST['Q3p2'];
	$Q3p3 = $_POST['Q3p3'];
	$Q3p4 = $_POST['Q3p4'];
	$Q3p5 = $_POST['Q3p5'];
	$Q4p1 = $_POST['Q4p1'];
	$Q4p2 = $_POST['Q4p2'];
	$Q4p3 = $_POST['Q4p3'];
	$Q4p4 = $_POST['Q4p4'];
	$Q4p5 = $_POST['Q4p5'];
	$Q5p1 = $_POST['Q5p1'];
	$Q5p2 = $_POST['Q5p2'];
	$Q5p3 = $_POST['Q5p3'];
	$Q5p4 = $_POST['Q5p4'];
	$Q5p5 = $_POST['Q5p5'];
	$total = $_POST['total'];
	$assSurname = $_POST['assSurname'];
	$assYrGroup = $_POST['assYrGroup'];
	$assBooklet = $_POST['assBooklet'];
	$assessment = $_POST['assessment'];

	// ** VALIDATION CHECKS ON TEXTBOXES **
	if($Q1p1 == "") 
	{
		$message11 = "* Please enter the student's score";
	}
	if($Q1p2 == "") 
	{
		$message12 = "* Please enter the student's score";
	}
	if($Q1p3 == "") 
	{
		$message13 = "* Please enter the student's score";
	}
	if($Q1p4 == "") 
	{
		$message14 = "* Please enter the student's score";
	}
	if($Q1p5 == "") 
	{
		$message15 = "* Please enter the student's score";
	}
	if($Q2p1 == "") 
	{
		$message21 = "* Please enter the student's score";
	}
	if($Q2p2 == "") 
	{
		$message22 = "* Please enter the student's score";
	}
	if($Q2p3 == "") 
	{
		$message23 = "* Please enter the student's score";
	}
	if($Q2p4 == "") 
	{
		$message24 = "* Please enter the student's score";
	}
	if($Q2p5 == "") 
	{
		$message25 = "* Please enter the student's score";
	}
	if($Q3p1 == "") 
	{
		$message31 = "* Please enter the student's score";
	}
	if($Q3p2 == "") 
	{
		$message32 = "* Please enter the student's score";
	}
	if($Q3p3 == "") 
	{
		$message33 = "* Please enter the student's score";
	}
	if($Q3p4 == "") 
	{
		$message34 = "* Please enter the student's score";
	}
	if($Q3p5 == "") 
	{
		$message35 = "* Please enter the student's score";
	}
	if($Q4p1 == "")
	{
		$message41 = "* Please enter the student's score";
	}
	if($Q4p2 == "")
	{
		$message42 = "* Please enter the student's score";
	}
	if($Q4p3 == "")
	{
		$message43 = "* Please enter the student's score";
	}
	if($Q4p4 == "")
	{
		$message44 = "* Please enter the student's score";
	}
	if($Q4p5 == "")
	{
		$message45 = "* Please enter the student's score";
	}
	if($Q5p1 == "")
	{
		$message51 = "* Please enter the student's score";
	}
	if($Q5p2 == "")
	{
		$message52 = "* Please enter the student's score";
	}
	if($Q5p3 == "")
	{
		$message53 = "* Please enter the student's score";
	}
	if($Q5p4 == "")
	{
		$message54 = "* Please enter the student's score";
	}
	if($Q5p5 == "")
	{
		$message55 = "* Please enter the student's score";
	}
	if($assYrGroup == "[select Year Group]")
	{
		$message6 = "* Please select a Year Group";
	}
	if($assessment == "[select Assessment]")
	{
		$message7 = "* Please select the Assessment";
	}
	if($assBooklet == "[select Booklet]")
	{
		$message8 = "* Please select the Booklet";
	}
	else
	{

//** RUNS A COUNT TO SEE IF THE PRODUCT ALREADY EXISTS ON THE SYSTEM **
	$query2 = "SELECT COUNT(*) FROM assessment WHERE assSurname='" . mysql_real_escape_string($assSurname) . "' AND assYrGroup='" . mysql_real_escape_string($assYrGroup) . "' AND assessment='" . mysql_real_escape_string($assessment) . "'";
	$result2 = mysql_query($query2, $connection) or die ("Unable to perform query<br>$query2");
	$row2= mysql_fetch_row($result2);
    	$count = $row2[0];
	if($count)
	{
      		$message11 .= 'That student already has a completed score for that assessment.<br>';
	}
    	else
    	{

		//** RUNS THE INSERT QUERY **
		$query = "insert into assessment values ('','".$Q1p1."','".$Q1p2."','".$Q1p3."','".$Q1p4."','".$Q1p5."','".$Q2p1."','".$Q2p2."','".$Q2p3."','".$Q2p4."','".$Q2p5."','".$Q3p1."','".$Q3p2."','".$Q3p3."','".$Q3p4."','".$Q3p5."','".$Q4p1."','".$Q4p2."','".$Q4p3."','".$Q4p4."','".$Q4p5."','".$Q5p1."','".$Q5p2."','".$Q5p3."','".$Q5p4."','".$Q5p5."','".$assessment."','".$assYrGroup."','".$assBooklet."','".$assSurname."')";
		$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");
		$message9 = "Scores submitted successfully. ";

		$Q1p2 = "";
		$Q1p3 = "";
		$Q1p4 = "";
		$Q1p5 = "";
		$Q2p1 = "";
		$Q2p2 = "";
		$Q2p3 = "";
		$Q2p4 = "";
		$Q2p5 = "";
		$Q3p1 = "";
		$Q3p2 = "";
		$Q3p3 = "";
		$Q3p4 = "";
		$Q3p5 = "";
		$Q4p1 = "";
		$Q4p2 = "";
		$Q4p3 = "";
		$Q4p4 = "";
		$Q4p5 = "";
		$Q5p1 = "";
		$Q5p2 = "";
		$Q5p3 = "";
		$Q5p4 = "";
		$Q5p5 = "";

		}	
	}
}
?>

Many thanks

Link to comment
Share on other sites

What happens is it wont let me pass the values back into the textboxes aswell as the studentID through the URL.

If i comment out the pagemode code or the passing of the studentID throught the URL it allows it but with both of them in there it doesn't like it.

 

Any suggestions? PLEASE  ???

Link to comment
Share on other sites

I'm not 100% sure i follow your question/problem but have you considered using a hidden field for your student id? Either that, or make sure you're appending the id to the action of the form.

 

On a side note, you'd be able to clean your code up an awful lot if you used arrays to collect the scores.

Link to comment
Share on other sites

Oh ok, any chance in showing me how to tidy up my code while we are here!? :)

 

Ok, so what happens is the user selects a student from student.php and clicks on their surname which then passes the studentID to the newAssessment.php page (shown above) using

<a href="newAssessment.php?studentID=<?php echo $row['studentID']?>"><?php echo $row['studentID']?>

I have validation in place that if the user clicks submit when there is a textbox that is empty an error message appears but in order for better usability it passes the values already in the textboxes back into the textboxes so they do not need to re-enter all the info. Unfortunately as I am already asking the page to carry over the studentId when the user submits the info with an empty textbox i get this error message...

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

Hope this helps.

 

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.