Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    brk
    brk is offline
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP Script issue (quiz script)

    Hello,

    So I have a script which is basically a quizish thing. I have an admin panel where I introduce questions and I select the correct answers. Also, I am able to select multiple correct answers if that is needed. Now what is the problem. I have a question with 4 choices and I want to make 2 choices correct.

    The choices are A, B, C, D.

    If I set B,C as correct, it's ok, after I save the question those are set to be the correct choices. If I set B, D it's ok again, after saving the question, the correct choices are saved. Now, if I want to set A, B as the correct choices, after saving it's saved only B. However, if I set A,D or A,C, the choices are saved.

    It seems like there is a conflict between setting correct choices A, B. After saving only B is there.

    Here is a demo of the script, of the admin panel:

    http://stilbarbatesc.ro/ap/admin

    user: demo

    pass: demo

    After entering please go to "Intrebari" and after that choose "PROF.LEG.RUT - INSTRUCTORI AUTO" (it's at the end of the first list)


    After choosing "PROF.LEG.RUT - INSTRUCTORI AUTO" you will see bellow the questions of this test. Just go on whatever question you want and try setting the correct choices (Varianta corecta)

    A and B. Save that and go back to the question, you will see that only B got saved.

    Here is also a snippet of the code, maybe will help.

    Code:
    <?php
    $target = "../files/img_intrebari/";
    if(empty($_GET['pagina'])) {$_GET['pagina'] = 'adauga-intrebare';}
    if(empty($_GET['id']))
    { $teste = mysql_query("SELECT * FROM teste where test_tip='parinte' order by test_nume limit 1"); }
    else { $teste = mysql_query("SELECT * FROM teste where test_id='$_GET[id]'"); }
    
    while($row = mysql_fetch_assoc($teste))
    {
        $_GET['id'] = $row['test_id'];
        if($row['test_numar_variante'] == 'Doar o varianta')
        {
            $test_numar_variante = 'radio';
            $test_numar_variante_a = 'int_var_cor_a';
            $test_numar_variante_b = 'int_var_cor_a';
            $test_numar_variante_c = 'int_var_cor_a';
            $test_numar_variante_d = 'int_var_cor_a';
            $test_numar_variante_e = 'int_var_cor_a';
            $test_numar_variante_n = 'int_var_cor_a';
        }
        elseif($row['test_numar_variante'] == 'Toate variantele')
        {
            $test_numar_variante = 'checkbox';
            $test_numar_variante_a = 'int_var_cor_a';
            $test_numar_variante_b = 'int_var_cor_b';
            $test_numar_variante_c = 'int_var_cor_c';
            $test_numar_variante_d = 'int_var_cor_d';
            $test_numar_variante_e = 'int_var_cor_e';
            $test_numar_variante_n = 'int_var_cor_n';
        }
    }
    
    if(isset($_POST['adauga']) or isset($_POST['salveaza']))
    {
        $intrebare = mysql_real_escape_string($_POST['intrebare']);
        $intrebare_var_a = mysql_real_escape_string($_POST['intrebare_var_a']);
        $intrebare_var_b = mysql_real_escape_string($_POST['intrebare_var_b']);
        $intrebare_var_c = mysql_real_escape_string($_POST['intrebare_var_c']);
        $intrebare_var_d = mysql_real_escape_string($_POST['intrebare_var_d']);
        $intrebare_var_e = mysql_real_escape_string($_POST['intrebare_var_e']);
        $variante = '';
        if(!empty($_POST['int_var_cor_a'])) {$variante = $variante.$_POST['int_var_cor_a'].',';}
        if(!empty($_POST['int_var_cor_b'])) {$variante = $variante.$_POST['int_var_cor_b'].',';}
        if(!empty($_POST['int_var_cor_c'])) {$variante = $variante.$_POST['int_var_cor_c'].',';}
        if(!empty($_POST['int_var_cor_d'])) {$variante = $variante.$_POST['int_var_cor_d'].',';}
        if(!empty($_POST['int_var_cor_e'])) {$variante = $variante.$_POST['int_var_cor_e'].',';}
        if(!empty($_POST['int_var_cor_n'])) {$variante = $variante.$_POST['int_var_cor_n'].',';}
        $intrebare_var_cor = substr($variante,0,-1);
        
        $intrebare_test_id = $_GET['id'];
        
        if(empty($intrebare))
        { $_SESSION['mesaj-e'] = 'Intrebarea contine prea putine caractere !'; redirect(); }
        
        if(empty($intrebare_var_a) and empty($intrebare_var_b) and empty($intrebare_var_c) and empty($intrebare_var_d) and empty($intrebare_var_e))
        { $_SESSION['mesaj-e'] = 'Variantele de raspuns nu contin caractere ! Este necesara cel pul o varianta de raspuns !'; redirect(); }
        
        if(empty($intrebare_var_cor))
        { $_SESSION['mesaj-e'] = 'Nu a fost selectata nici o varianta corecta !'; redirect(); }
        
        if(isset($_POST['adauga']))
        {
            $insert = mysql_query("INSERT INTO `intrebari` (intrebare,intrebare_var_a,intrebare_var_b,intrebare_var_c,intrebare_var_d,intrebare_var_e,intrebare_var_cor,intrebare_test_id) values ('$intrebare','$intrebare_var_a','$intrebare_var_b','$intrebare_var_c','$intrebare_var_d','$intrebare_var_e','$intrebare_var_cor','$intrebare_test_id')");
        }
        elseif(isset($_POST['salveaza']))
        {
            $insert = mysql_query("UPDATE `intrebari` SET intrebare='$intrebare',intrebare_var_a='$intrebare_var_a',intrebare_var_b='$intrebare_var_b',intrebare_var_c='$intrebare_var_c',intrebare_var_d='$intrebare_var_d',intrebare_var_e='$intrebare_var_e',intrebare_var_cor='$intrebare_var_cor',intrebare_test_id='$intrebare_test_id' where intrebare_id='$_GET[pagina]'");
        }
        if($insert)
        {
            if(isset($_POST['adauga']))
            {
                $verificare = mysql_query("SELECT * FROM `intrebari` order by `intrebare_id` DESC LIMIT 1");
                while( $row = mysql_fetch_assoc($verificare) ) {$_POST['intrebare_id'] = $row['intrebare_id'];}
            }
            elseif(isset($_POST['salveaza']))
            {
            $_POST['intrebare_id'] = $_GET['pagina'];
            }
            
            $imagine = $target.str_replace(basename($_FILES['imagine']['name']),$_POST['intrebare_id'].'.png',basename($_FILES['imagine']['name']));
            move_uploaded_file($_FILES['imagine']['tmp_name'], $imagine);
            
            if(isset($_POST['adauga']))
            {
                $_SESSION['mesaj-s'] = 'Intrebarea a fost adaugata !';
            }
            elseif(isset($_POST['salveaza']))
            {
                $_SESSION['mesaj-s'] = 'Datele intrebarii s-au salvat !';
            }
            
        }
        else {die(mysql_error()); $_SESSION['mesaj-e'] = 'A avut loc o eroare !';}
        redirect();
    }
    
    if(!empty($_GET['sterge']))
    {
        if(unlink($_GET['sterge']))
        { $_SESSION['mesaj-s'] = 'Imaginea a fost stearsa !'; }
        else { $_SESSION['mesaj-e'] = 'A avut loc o eroare !'; }
        redirect_action();
    }
    
    if(isset($_POST['sterge'])){ $_GET['actiune'] = 'sterge-intrebare'; }
    
    if(!empty($_GET['confirm']) and $_GET['confirm'] == 'da')
    {
        $delete = mysql_query("DELETE FROM `intrebari` where intrebare_id='$_GET[pagina]'");
        if($delete)
        {
            unlink($target.$_GET['pagina'].'.png');
            $_SESSION['mesaj-s'] = 'Intrebarea a fost stearsa !';
        }
        else { $_SESSION['mesaj-e'] = 'A avut loc o eroare !'; }
        redirect_page();
    }
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Explain why question "A" has an 'e' ....

    <input type="checkbox" name="int_var_cor_e" value="A" class="inline" checked />



    EDIT:
    Now I see something ....
    Each test is different.
    Running it again, this is the "A" checkbox:
    <input type="checkbox" name="int_var_cor_b" value="A" class="inline" />

    That is suspicious, because if you check the A checkbox, the name of that is 'int_var_cor_b'
    I picked different questions and then looked again at the HTML source, and the "A" name changes.
    I would think that the "A" question should always be: 'int_var_cor_a'



    .
    Last edited by mlseim; 04-18-2013 at 08:41 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •