0

Here is my code, I understand that it is important to not mix html and php together on the same lines, but I can't get my head around this! Can anyone be of assistance? I have tried a few alternatives but I keep getting the syntax error unexpected '}'.

    <?php //Creating random number s
     $rid = rand(1,3); 
     echo $rid; if ($rid == 1){ ?>


     <form action="<?php echo base_url(); ?>index.php/welcome/result" method='post' id='quizForm' id='1'>

    <input type="hidden" name="id" value="1"/>
    <ol>


    <li>
    <h3>What does PHP stand for?</h3>

    <div>
    <input type='radio' name='answerOne' id='answerOne' value='A' />
    <label for='answerOneA'>A) Hyper text markup language</label>
    </div>

    <div>
    <input type='radio' name='answerOne' id='answerOne' value='B' />
    <label for='answerOneB'>B) PHP: Preprocessed hypertext</label>
    </div>

    <div>
    <input type='radio' name='answerOne' id='answerOne' value='C' />
    <label for='answerOneC'>C) PHP: Hypertext Preprocessor</label>
    </div>
    </li>


    <li>
    <h3>Who invented PHP?</h3>

    <div>
    <input type='radio' name='answerTwo' id='answerTwo' value='A' />
    <label for='answerTwoA'>A) Dick Dastardly </label>
    </div>

    <div>
    <input type='radio' name='answerTwo' id='answerTwo' value='B' />
    <label for='answerTwoB'>B) Rasmus Lerdof</label>
    </div>

    <div>
    <input type='radio' name='answerTwo' id='answerTwo' value='C' />
    <label for='answerTwoC'>C) God</label>
    </div>
    </li>



     <li>
    <h3>What is PHP used for?</h3>

    <div>
    <input type='radio' name='answerThree' id='answerThree' value='A' />
    <label for='answerThreeA'>A) Creating dynamic webpages</label>
    </div>

    <div>
    <input type='radio' name='answerThree' id='answerThree' value='B' />
    <label for='answerThreeB'>B) Server-side scripting</label>
    </div>

    <div>
    <input type='radio' name='answerThree' id='answerThree' value='C' />
    <label for='answerThreeC'>C) All of the above</label>
    </div>
    </li>
    </ol>
    <input type='submit' value='Submit Answers' />

    </form>
    <?php
     }
     ?>
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
KGdB
  • 59
  • 1
  • 5
  • 2
    You don't put another echo statement in a echo statement! Concatenate your strings! – Rizier123 May 05 '15 at 10:26
  • 1
    This question has many answers already but you can decide to do `` Output all your HTML then open PHP again and close the open if statement `` – OmniPotens May 05 '15 at 10:30
  • sorry could you make that a little clearer for me please? I haven't slept for 2 days and my brain cannot function right now! – KGdB May 05 '15 at 10:34
  • apologies again, tried your method out @OmniPotens and it worked, thanks! – KGdB May 05 '15 at 10:38
  • @KGdB Great it helped you. You can mark my solution up so others seeking a near solution can look it up for assistance. – OmniPotens May 05 '15 at 10:44
  • only one problem though, when i reopen the php tags for '}' after closing the form tag, it gives me an error saying unexpected '}'. it seems to be one error after the other with me :( – KGdB May 05 '15 at 10:55
  • @OmniPotens any ideas on where it's going wrong? – KGdB May 05 '15 at 11:03
  • You see, you called `echo` and after it you opened with `"YOUR HTML"` and inside of your form you have `
    – OmniPotens May 05 '15 at 11:14
  • uh not entirely. I opened the php and closed it before the html, then after closing the html i reopened php to declare '}'. However the syntax error is saying this shouldn't be there? – KGdB May 05 '15 at 11:16
  • @OmniPotens I have updated my code to show you what I mean. – KGdB May 05 '15 at 11:26
  • now it's decided to change to unexpected end of file...... – KGdB May 05 '15 at 11:28
  • I believe my explanation has simplified the process. If you are still lost, create a chat room and invite me so I give your different instances on how to handle the scenario so you don't run into troubles next time as I see you are likely a beginner on the language. – OmniPotens May 05 '15 at 11:33
  • I don't think I have enough reputation to join a chatroom let alone create a chat room :P – KGdB May 05 '15 at 11:39

0 Answers0