Jump to content


Photo

syntax question


  • Please log in to reply
7 replies to this topic

#1 nawhaley2265

nawhaley2265
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 June 2006 - 12:48 PM

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

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 
       
      }

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?

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 20 June 2006 - 12:56 PM

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.
wisewood: proven fact, I am both wise, and wooden.

#3 nawhaley2265

nawhaley2265
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 June 2006 - 01:01 PM

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.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 June 2006 - 01:57 PM

If you comment out that section, does the error disappear?

Ken

#5 nawhaley2265

nawhaley2265
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 June 2006 - 02:26 PM

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.

#6 nawhaley2265

nawhaley2265
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 June 2006 - 02:47 PM

oddly it wont let me post any code now :/

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 June 2006 - 02:53 PM

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:
<?php $x = fopen ('test'.'w'); ?>

Ken

#8 nawhaley2265

nawhaley2265
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 June 2006 - 03:38 PM

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

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'] = "";
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users