Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Irate

  1. Hey there, so, basically, I have been reading a few tutorials about making a quiz with PHP, so I decided to write my own quiz, but I am stuck at the answer validation action because I do not know how to properly do so (I am a bit new to PHP, too), so I decided to ask about this. I haven't got a mysql db yet, that noted, and I want the whole quiz to be displayed within an iframe html tag on another site of mine which does not support PHP hosting itself. Code: <?php // quiz.php header("Content-Type: text/html; charset=utf-8"); ?> <!-- exclude basic html skeleton --> <form action="validate.php" method="post"> Question 1: Question Text <input type="radio" value="0">Answer 1 (false, as value="0" indicates)<br> <!-- repeat two more times --> <input type="radio" value="1">Answer 4 (this is my correct answer)<br> <!-- repeat questions until #35 --> <!-- end quiz.php, close html tags --> <?php // validate.php $res = 0; foreach($_POST as $score){ // get all answers from post array $res = $res + $score; } switch($res){ // do switch statement to avoid endless elseif statements because we have many answers case 35: echo "To submit your score, press the button below.<br><form action='http://forum.forumotion.com/posting.forum?' method='post'> <textarea style='display: none;'>Scored ".$res." out of 35 possible points.</textarea> <input type='submit'></form>"; exit; break; case 34: // repeat until reached at 0 echo "..."; exit; break; } ?> The forum URL specified within validate.php is fictional, by the way, but my forum host uses /posting.forum? for its post action. Thing is, I don't want to specify the value of the answers with HTML because about everyone could inspect the HTML code of the iframe and get every answer correct... I want to prevent that, of course. Anyone help?
  2. The regex would look like this... /(?=<\!DOCTYPE\shtml(\s[public])?[\s]?[('|")(.*)('|")]?[('|")(.*).('|")]?>)/i This should match the first string starting with <!DOCTYPE html>, followed by an optional ' public', another optional whitespace and an optional occurence of any string within quotes, which then is repeated to match an optional url and a final larger than sign. The whole search is case-insensitive. But, with HTML5, it'd simply be this: /^<\!DOCTYPE\shtml>/i, because you needn't declare public and add -//, nor the url. Hope this works.
    1. Philip


      $Phil->status = 'great!';

    2. Irate


      var irate = { status_reply: "That's cool. I hope to improve my PHP skills here, and not just a little.", emotion: undefined }; document.write(irate.status_reply); irate.emotion = "Happy.";

  3. https://developer.mozilla.org/en-US/docs/HTML/Element/iframe It seems to be able to work in all implementations of HTML5. So, try setting the sandbox attribute to allow-scripts and then testing it within a HTML5 supported browser.
  4. I'm sorry... I haven't really been through MySQL and thought it was the same...
  5. Where do you that line? I do not see it anywhere in your code...
  6. Try htmlspecialchars() to escape all ', ", < and > within submitted data. I would make an example but my mobile phone is very limited there.
  7. You need to set the allowScriptAccess attribute within the iframe tag to "always", otherwise, due to the same origin policy, no scripts will be executed as the default is "sameOrigin". Like this: <iframe allowScriptAccess='always' name='myIframe' id='myIframe' src='http://reports/Repor...t=my_htmlviewer' height='650' width='100%' scrolling='auto' frameborder='0' ></iframe>
  8. If you want to use a variable in jQuery with $ in its name, you have to call jQuery.noConflict(); and need to refer to all jQuery functions with jQuery(). Also try firing the whole event on jQuery(document).ready(function(){});
  9. Hey everyone, I'm 16 years old and from Vienna and recently got into PHP. I already have advanced HTML Skills and I am an about average (possibly a bit above average) JavaScript scripter, everything I know about PHP and JavaScript I have learned from various books and I already have a working PHP surrounding. Anyway, I wanted to know if I am the only underage coder here or if there's anyone from Vienna with the same interests as I have them at my age. Hope I can get along with everyone, ~ Irate
  • 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.