Jump to content

syntax question


nawhaley2265

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?
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.