nawhaley2265 Posted June 20, 2006 Share Posted June 20, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/ Share on other sites More sharing options...
wisewood Posted June 20, 2006 Share Posted June 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47638 Share on other sites More sharing options...
nawhaley2265 Posted June 20, 2006 Author Share Posted June 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47641 Share on other sites More sharing options...
kenrbnsn Posted June 20, 2006 Share Posted June 20, 2006 If you comment out that section, does the error disappear?Ken Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47664 Share on other sites More sharing options...
nawhaley2265 Posted June 20, 2006 Author Share Posted June 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47675 Share on other sites More sharing options...
nawhaley2265 Posted June 20, 2006 Author Share Posted June 20, 2006 oddly it wont let me post any code now :/ Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47679 Share on other sites More sharing options...
kenrbnsn Posted June 20, 2006 Share Posted June 20, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47684 Share on other sites More sharing options...
nawhaley2265 Posted June 20, 2006 Author Share Posted June 20, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/12462-syntax-question/#findComment-47703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.