0

hi...I have three different ph files that received value from those files...

class_survey.php

<?php
class surveyForm
{
function selectForm()
{
   //query to display form
}
function insert_survey_result($rating, $form)
{
   if($form=="survey1")
   {
        echo "form: $form";  //check whether the form passing at here is correct
        for($j=1;$j<=count($rating);$j++)
       {	
           echo $sql1 = "INSERT INTO survey_result1 (rating) VALUES ('$rating[$j]');
           mysql_query($sql1);			
       }
   }
   elseif($form=="survey2")
   {
       echo "form: $form";  //check whether the form passing at here is correct
        for($j=1;$j<=count($rating);$j++)
       {	
           echo $sql2 = "INSERT INTO survey_result2 (rating) VALUES ('$rating[$j]');
           mysql_query($sql2);			
       }
   }
   else
  {
       echo "form: $form";  //check whether the form passing at here is correct
        for($j=1;$j<=count($rating);$j++)
       {	
            echo $sql3 = "INSERT INTO survey_result3 (rating) VALUES ('$rating[$j]');
           mysql_query($sql3);			
       }
   }
   echo "after_if_else_statement: $form";
}
}
?>

survey.php

<?php
session_start();
include("../class_survey.php");
$form = $_GET['form'];
$selectForm = new surveyForm();
?>
<a href="../assessmentForm/s_proposal.php?form=survey1">Survey Form 1</a>
<a href="../assessmentForm/s_proposal.php?form=survey2">Survey Form 2</a>
<a href="../assessmentForm/s_proposal.php?form=survey3">Survey Form 3</a>
<form name="survey" id="survey" method="post" action="survey_code.php" onSubmit="return validate()"> 
<?php $selectForm->surveyForm($form); ?>   //display selected form
<input name="form" type="hidden" id="form" value="<?php echo $form; ?> ">

survey_code.php

<?php
$rating = $_POST['rating'];
$form = $_POST['form'];
echo "code: $form";   //check whether the form passing at here is correct

$survey_result = new surveyForm();
$survey_result->insert_survey_result($rating, $form);
?>

output
code: survey1
form: survey1
INSERT INTO survey_result3 (rating) VALUES ('5')
INSERT INTO survey_result3 (rating) VALUES ('5')
after_if_else_statement: survey1

It is very strange things because the form (survey1) passing to every php files is correct but when read the if...else statement, it only read the else statement...but the the form running in the if...else statement is the form passing to the function...as the above example...the form is survey1 and although it read the else statement (which is suppose form for survey3 will run this statement) but the form is still survey1...I already try for many method to solve this problem...but also not what I expected...anyone got comment on this??thanks...

5
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by star_lavender
0

Don't see what could be wrong your code. If I do this:

<?php

function what_form($form) {
	if ($form=="survey1") {
		echo "survey1\n";
	}
	elseif ($form=="survey2") {
		echo "survey2\n";
	}
	else {
		echo "survey3\n";
	}
	return;
}

what_form("survey1");
what_form("survey2");
what_form("survey3");
?>

the output is survey1, survey2, survey3.
It must have something to do with the way you select the form that is posted to "class_survey.php". Maybe you could replace the if..else with a switch like so:

function what_form($form) {
	switch ($form) {
		case ($form=="survey1") : echo "survey1\n"; break;
		case ($form=="survey2") : echo "survey2\n"; break;
		case ($form=="survey3") : echo "survey3\n"; break;
	}
	return;
}

what_form("survey1");
what_form("survey2");
what_form("survey3");
?>

But I don't know if that would solve your problem.

0

well, I am not feeling well naming an iput as "form" try changing it, I would be surprised if this was the problem :P

0

You do know lines 15, 24 and 33 are missing closing double quotes don't you. This will certainly cause the problem you're complaining of.

Edited by pclfw: n/a

0

ya...I got close the statement in my coding...miss to close in this thread...

You do know lines 15, 24 and 33 are missing closing double quotes don't you. This will certainly cause the problem you're complaining of.

0

thanks for the reply... but the problem still the same...

well, I am not feeling well naming an iput as "form" try changing it, I would be surprised if this was the problem :P

0

first,thanks for the reply...yes, I try switch case also before this...but still didn't work...
may I know that is the code below are outside the function??but if put outside the function why got error...

what_form("survey1");
what_form("survey2");
what_form("survey3");

if put inside the function, the switch case didn't work...

class survey
{
        function what_form($form) {
	switch ($form) {
		case ($form=="survey1") : echo "survey1\n"; break;
		case ($form=="survey2") : echo "survey2\n"; break;
		case ($form=="survey3") : echo "survey3\n"; break;
	}
	return;
}

what_form("survey1");
what_form("survey2");
what_form("survey3");
}
?>

Don't see what could be wrong your code. If I do this:

<?php

function what_form($form) {
	if ($form=="survey1") {
		echo "survey1\n";
	}
	elseif ($form=="survey2") {
		echo "survey2\n";
	}
	else {
		echo "survey3\n";
	}
	return;
}

what_form("survey1");
what_form("survey2");
what_form("survey3");
?>

the output is survey1, survey2, survey3.
It must have something to do with the way you select the form that is posted to "class_survey.php". Maybe you could replace the if..else with a switch like so:

function what_form($form) {
	switch ($form) {
		case ($form=="survey1") : echo "survey1\n"; break;
		case ($form=="survey2") : echo "survey2\n"; break;
		case ($form=="survey3") : echo "survey3\n"; break;
	}
	return;
}

what_form("survey1");
what_form("survey2");
what_form("survey3");
?>

But I don't know if that would solve your problem.

0

Can't say I follow what you're trying to do here, but are you sure that this line is right:

$selectForm->surveyForm($form);

0

typing error at here...
I can get my survey form correctly but the problem appear at if...else statement...

Can't say I follow what you're trying to do here, but are you sure that this line is right:

$selectForm->surveyForm($form);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.