Jump to content

Error in code


bumdeal2

Recommended Posts

I have two forms that pass info between each other (quesid),the problem i am having is when i pass he value from one form to another, the vaue being passed in the url is $quesie, i dont know where the $quesie is coming froma it is not in my code could u please help.

 

My first form is

1.

<?php


include('auth.php');
include('database_access_param.php');
include('auth.php');

$qid=$_POST['qid'];
$qzid=$_POST['qzid'];
$quesid=$_POST['quesid'];


if(isset($_GET['quesid'])) {

   $quesid=$_GET['quesid'];
}

if(isset($_GET['qid'])) {

   $qzid=$_GET['qid'];

}

echo $quesid;
echo $qzid;

    mysql_connect( $hostname, $dbuser, $dbpassword)
        or die ( 'Unable to connect to server' );

    

    mysql_select_db($dbname )
        or die ( 'Unable to select database' );


    $sql = "SELECT * FROM questiona WHERE qzid = '$qzid' && quesid = '$quesid' ";


	print("</head>");
	print('<body>');
	print('<form action="grad.php?quesid=$quesid" method="post" id="quiz">');
	print('<table class="report" align=left width=100%>');

	print('<tr><td> </td></tr>');


	$result=mysql_query($sql) or die ('Unable execute the query');
;


	if(mysql_numrows($result))
	{
			$row = mysql_fetch_row($result);
			{

			$questid=$row[0];
			$quesid=$row[1];
			$question=$row[2];
			$answer=$row[3];
			$ranswer=$row[4];
			$ranswer1=$row[5];
			$ranswer2=$row[6];




print('<tr><td >'.$quesid.'   '.$question.'</td>'.$Quiz_Topic.'</tr>');

      
print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer .'">   '.$ranswer.'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer1 .'">   '.$ranswer1 .'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer2 .'">   '.$ranswer2 .'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="answer">   '.$answer .'</td></tr>');

print('<tr><td> <input type=hidden name=answer value="'.$answer.'"><input type= hidden name=quesid value="$quesid"></tr>');


}
print('<tr><td colspan=2><input type=submit name=submit value="Submit" ><input type=reset name=reset value="Clear" ></td></tr></table>');
}
else
{

 echo "<div id='results'>Your result is:  $subTotal%</div>";
print('<input type =hidden name=score value="'.$score.'">');
print('</form>');

}




?>

 

 

 

 

 

My second page  is

1.

<

?php


include('auth.php');
include('database_access_param.php');
import_request_variables("pgc","");

//echo" act_save_answer.php<br>";
$quesid = $_POST['quesid'];
$qzid= $_POST['qzid'];
$answer = $_POST['answer'];

$exist=0;
$score=0;
$cday= date('d');
$cmonth= date('m');
$cyear= date('Y');



$dbcurrent_date=$cyear.'-'.$cmonth.'-'.$cday;



$db_link=mysql_connect($hostname, $dbuser, $dbpassword) or die("Unable to connect to the server!");

	mysql_select_db($dbname) or die("Unable to connect to the database.");


	$ssql = "SELECT * FROM scores WHERE
                username = '$user' AND
                qid = '$qid'";

if($quesid<11)

{ 

            
            $totalCorrect = 0;
            
            if ($answer == "answer") { $totalCorrect++; }
           

    $num = 10;

    $subTotal = $totalCorrect * $num;


            $subTotal;




$quesid++;


header("location: PlayGame.php?quesid=$quesid ");

if($quesid=11)

{ 

$isql="insert into scores(scoreid,qid, username, score, qdate) values
		                         (0, '".$user."','".$qid."',".$subTotal.",'".$dbcurrent_date."')";
//echo $isql."<br>";

					if(!mysql_query($isql))
					{
					echo mysql_errno() . ": ";
					echo mysql_error() . "<BR>";
					}


}						

}

else
							{
							echo "Sorry. You cannot take this quiz second time!";
							print('<a href="index.php?boxaction=home">Home</a>');
							}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/197467-error-in-code/
Share on other sites

It's coming from right here:

 

print('<form action="grad.php?quesid=$quesid"

 

I believe you're looking for:

 

print('<form action="grad.php?quesid='.$quesid.'"

 

Keep in mind, you're using single quotes for this string, so variables inside single quotes are NOT parsed:

 

$example_string = 'stuff';
echo 'This is the first example: '.$example_string; // This is the first example: stuff
echo 'This is the second example: $example_string'; // This is the second example: $example_string
echo "This is the third example: $example_string"; // This is the third example: stuff

Link to comment
https://forums.phpfreaks.com/topic/197467-error-in-code/#findComment-1036514
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.