Jump to content

Archived

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

nawhaley2265

syntax question

Recommended Posts

Hey everyone I'm working on debugging a app of mine written in php and I keep having an error come up on the following code

[code]
if($qtype =="S" && $count > 1 )
      {
      ?>
       <script LANGUAGE ="javascript" TYPE ="text/javascript">
       alert("There is more than one correct answer to this question now. Please correct before you finish editing!");
       </SCRIPT>
       <?php
      
      }
[/code]

it keeps telling me there is an unexpected } in this code. Now I've checked all the syntax around this code and it all looks fine its just this one segment that causes issues to crop up. Is there something against PhP version 5.1.4 and using javascript in this manner? Is there any workaround I can do to leave it basically functioning the same way?

Share this post


Link to post
Share on other sites
I've had problems in the past similar to this, and often the area where it tells you to look for the problem is wrong when its an unexpected }.

You'd need to examine all of your code carefully and check to see if you've got any un-necessary or out of place.

Share this post


Link to post
Share on other sites
I thought the same thing to but I"m not finding anything else following the code thats causing the problem or before I'll look again though and see if I can find anything that might be causing this other than that one piece of code.

Share this post


Link to post
Share on other sites
If you comment out that section, does the error disappear?

Ken

Share this post


Link to post
Share on other sites
good question when I do comment it out it goes down to the end of the function and says that the } that ends the function is unexpected so it has to be something to do with a missing } somewhere which is odd because I don't recall this error appearing before I went from version 5.0.2 up to 5.1.4.

Share this post


Link to post
Share on other sites
If you have any functions in your code like fopen, there is a security check in this forum which thinks you are trying to hack the forum and refuses to let the post work. Just add a space between the function and the opening paranthesis:
[code]<?php $x = fopen ('test'.'w'); ?>[/code]

Ken

Share this post


Link to post
Share on other sites
Ok here is the code I couldnt post before. Note that if I comment the entire function save the brackets it still gives an error message stating that there is an unexpected } at the end of the function which is odd.

P.S. Thanks for the help in explaining why it wouldnt post Ken

[code]
function SaveEditAnswer()
{
   /*saves new answer where the answercode matches that stored in $acode*/
    $count = 1;
    $acode = $_SESSION['answer'];
    $correct =$_POST['answercorrect'];
    $link = odbc_connect ("ApplicantQuiz","UserName","password");
    $aquery = "SELECT * from tblAnswers WHERE AnswerCode ='$acode'";
    $aresult = odbc_exec ($link,$aquery);
    $answer = odbc_result ($aresult,"Answer");
    $question =odbc_result ($aresult,"QuestionCode");
    $qquery ="SELECT QuestionType from tblQuestions WHERE QuestionCode ='$question'";
    $qresult = odbc_exec ($link,$qquery);
    $qtype = odbc_result ($qresult,"QuestionType");


    $rightwrong = odbc_result ($aresult,"Correct");

   if($rightwrong ==0 && $correct ==1):
      
        $count++;
     endif;

   if($qtype =="S" && $count > 1 )
      {
       ?>
       <script LANGUAGE ="javascript" TYPE ="text/javascript">
       alert("There is more than one correct answer to this question now. Please correct before you finish editing!");
       </SCRIPT>
       <?php
      
      }


    $newanswer = $_POST['newanswer'];
    $originalanswer = $answer;
    $editsql = "UPDATE tblAnswers SET Answer='$newanswer',Correct ='$correct' WHERE AnswerCode ='$acode'";
    $editresult = odbc_exec ($link,$editsql);
    $_SESSION['QA'] = "";
}
[/code]

Share this post


Link to post
Share on other sites

×

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.