php and forms issue
Posted: Tue Aug 02, 2005 2:53 pm
Ok I've been working on a php script all day and I'm to a point to where I'm not sure my syntax is right regarding one particular part. I have a php page for testing purposes called databasesessiontest.php which calls databasetest2.php through a function called writequestion() like so.
the next page then writes out the question after connecting to the database etc and uses the print function to print out the HTML like so.
the first time you run the page it works fine the function writes out the HTML and everything displays to my satisfaction. The issue arrises when you click the submit button on the databasetest2.php page. When you do this the next page is blank it will not print a single thing not even a submit button. I think the problem lies in the following line.
but I'm running out of ideas on how to test for the breakdown in the logic. I thought at first it was a syntax error but if it was nothing would print even the first time. It also cannot be the way the session is setup because the values change correctly from one page to the next(that much I was able to test). Does anyone more experienced than me have any thoughts on this at all? I'm pretty new to the PHP language and imagine its a simple logic error but its one I've been unable to find a solution to.
Code: Select all
<?
session_start();
include 'databasetest2.php';
$_SESSION["link"] = odbc_connect("data","name","password");
/* set up query for questions */
$_SESSION["questionquery"] = "Select * from tblQuestions";
$_SESSION["questionresults"] = odbc_exec($_SESSION["link"],$_SESSION["questionquery"]);
$_SESSION["questioncounter"] = 1;
$_SESSION["counter"] = 1;
/* find out type of question Single answer or multiple answer */
$typeofquestion = odbc_result($_SESSION["questionresults"],"QuestionType");
while(odbc_fetch_row($_SESSION["questionresults"]))
{
$_SESSION["questioncounter"]++;
}
/*pull questioncode from the table tblQuestions*/
$questioncode = odbc_result($_SESSION["questionresults"],"QuestionCode");
/* get answers for the questions */
$queryanswers = "Select * from tblAnswers";
$answerresult = odbc_exec($_SESSION["link"],$queryanswers);
/*pull questioncode from tblAnswers*/
$ansquestioncode = odbc_result($answerresult,"QuestionCode");
writequestion();Code: Select all
function writequestion()
{
/*gets the type of questions and question itself from database results,prints question*/
print('<FORM METHOD = "POST" ACTION = "databasetest2.php">');
if( odbc_fetch_row($_SESSION["questionresults"],$_SESSION["counter"])):
$question = odbc_result($_SESSION["questionresults"],"Question");
$questioncode = odbc_result($_SESSION["questionresults"],"QuestionCode");
$typeofquestion = odbc_result($_SESSION["questionresults"],"QuestionType");
$queryanswers = "Select Answer from tblAnswers where QuestionCode ='$questioncode'";
$answerresult = odbc_exec($_SESSION["link"],$queryanswers);
print("$question"."<BR>");
/* if the question is a single answer S then print as radio button selection else use checkboxes*/
if($typeofquestion =="S"):
//print("hello S"."<BR>");
$answer = odbc_result($answerresult,"Answer");
$correct = odbc_result($answerresult,"Correct");
print('<INPUT TYPE = "radio" NAME = "answer" VALUE= "$correct">'."$answer"."<BR>");
while(odbc_fetch_row($answerresult))
{
$answer = odbc_result($answerresult,"Answer");
$correct = odbc_result($answerresult,"Correct");
print('<INPUT TYPE = "radio" NAME = "answer" VALUE= "$correct">'."$answer"."<BR>");
}
else:
while(odbc_fetch_row($answerresult))
{
print("hello M"."<BR>");
$answer = odbc_result($answerresult,"Answer");
$correct = odbc_result($answerresult,"Correct");
print('<INPUT TYPE = "checkbox" NAME = "answer" VALUE= "$correct">'."$answer"."<BR>");
}
endif;
print('<INPUT TYPE ="submit" VALUE = "submit">');
print('</FORM>');
$_SESSION["counter"]++;
endif;
}Code: Select all
print('<FORM METHOD = "POST" ACTION = "databasetest2.php">');