Jump to content

A script issue


brkrodj

Recommended Posts

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.

 

 

<?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();
}
?>
 
Link to comment
Share on other sites

I think the lack of response is indicative of the amount of Spanish-speakers on this website. It is hard to look through all your code not understanding the intention of the variables.

 

Could you be more specific about what area in the code is at fault? You say that you are "setting" choices. Is that in the database?

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.