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