示例#1
0
function insertToDatabase($xml)
{
    //kopplar in till database
    $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$mysqli) {
        echo "Det här gick ju inte så bra!";
    }
    //Tömmer tabellen så att den blir nollställd
    $mysqli->query("truncate apk_data");
    //sätter upp prepered
    $stmt = $mysqli->prepare("INSERT INTO apk_data (id,item_id,name,name2, department,volym,price, alcohol_by_volym, apk, status) VALUES (?,?,?,?,?,?,?,?,?,?)");
    $stmt->bind_param("iisssdddds", $id, $artikelid, $name, $name2, $department, $volym, $price, $alcoholByVolym, $apk, $status);
    $char = ",";
    $csvFile = "";
    //Loppar igenom alla artiklar
    foreach ($xml->artikel as $attribute) {
        $id = $attribute->nr;
        $artikelid = $attribute->Artikelid;
        $name = utf8_decode(deleteComma($attribute->Namn));
        $name2 = utf8_decode(deleteComma($attribute->Namn2));
        $department = utf8_decode(getDep($attribute->Varugrupp));
        $price = floatval($attribute->Pant) + floatval($attribute->Prisinklmoms);
        $volym = floatval($attribute->Volymiml);
        $alcoholByVolym = calcAlc($attribute->Alkoholhalt);
        $apk = calcAPK($price, $volym, $alcoholByVolym);
        $status = $attribute->Sortiment;
        //Kör satsen
        $stmt->execute();
    }
}
    }
}
?>
        </div>

        <form method="get" class="appnitro" action="">
            <label for="D_assoc">Selecionar Associado</label>
            <input id="D_assoc" type="text" name="D_assoc" placeholder="RG do associado" value="<?php 
echo @$_GET['D_assoc'];
?>
">
            <input type="submit" value="BUSCA">
        </form>
    <form id="form_1044499" class="appnitro"  method="post" action="">
        <?php 
if (isAssoc(@$_GET['D_assoc'])) {
    getAssoc($_GET['D_assoc']);
    echo "<br>";
    getDep($_GET['D_assoc']);
    print "\n <form id='form_1044499' class='appnitro'  method='post' action=''>\n <ul >\n             <li id='li_1' >\n                <label class='description' for='element_1'>Nome </label>\n\t\t<span>\n\t\t\t<input id='element_1_1' name='D_nome' class='element text'  maxlength='255' size='38' required/>\n\t\t\t<label>Nome completo</label>\n            </li>\n        <li id='li_3' >\n            <label class='description' for='element_3'>Data de nascimento </label>\n\t\t<span>\n            <input id='element_3_2' name='D_datanascDD' class='element text' size='2' maxlength='2' value='' type='number'> /\n\t\t\t<label for='element_3_2'>DD</label>\n\n\t\t</span>\n\t\t<span>\n\t\t\t<input id='element_3_1' name='D_datanascMM' class='element text' size='2' maxlength='2' value='' type='number'> /\n\t\t\t<label for='element_3_1'>MM</label>\n\t\t</span>\n\t\t<span>\n\t \t\t<input id='element_3_3' name='D_datanascYYYY' class='element text' size='4' maxlength='4' value='' type='number'>\n\t\t\t<label for='element_3_3'>YYYY</label>\n\t\t</span>\n\n\t\t<span id='calendar_3'>\n\t\t\t<img id='cal_img_3' class='datepicker' src='../img/calendar.gif' alt='Pick a date.'>\n\t\t</span>\n            <script type='text/javascript'>\n                Calendar.setup({\n                    inputField\t : 'element_3_3',\n                    baseField    : 'element_3',\n                    displayArea  : 'calendar_3',\n                    button\t\t : 'cal_img_3',\n                    ifFormat\t : '%B %e, %Y',\n                    onSelect\t : selectDate\n                });\n            </script>\n\n        </li>\n        <li id='li_10' >\n                <label class='description' for='element_10'>Grau de Parentesco </label>\n                <div>\n                    <select class='element select medium' id='element_10' name='D_parentesco' required>\n                        <option value='Mâe' >Mae</option>\n                        <option value='Pai' selected='selected'>PAI</option>\n                        <option value='Filho' >Filho</option>\n                        <option value='Filha'>Filha</option>\n                        <option value='Sobrinho' >Sobrinho</option>\n                        <option value='Sobrinha' >Sobrinha</option>\n                        <option value='Tio' >Tio</option>\n                        <option value='Tia' >Tio</option>\n                        <option value='Marido' >Marido</option>\n                        <option value='Esposa' >Esposa</option>\n                        <option value='Irmão' >Irmão</option>       \n                        <option value='Irmã' >Irmã</option>  \n                        <option value='Primo' >Primo</option>  \n                        <option value='Prima' >Prima</option>                                                                                   \n                        <option value='Sogro' >Sogro</option>     \n                        <option value='Sogra' >Sogra</option>  \n                        <option value='Outros' >Outros</option>                                                                 \n                    </select>\n                </div>\n            </li>\n\n            <li class='buttons'>\n                <input type='hidden' name='form_id' value='677' />\n\n                <input id='saveForm' class='button_text' type='submit' name='submit' value='Cadastrar' />\n            </li>\n        </ul>\n        </form>\n";
} else {
    echo "<p style='color: #22a20b;'>Busque por um associado para adicionar dependentte</p>";
}
?>

    <div id="footer">
    </div>
</div>
<img id="bottom" src="../img/bottom.png" alt="">
</body>
</html>
            </li>
        </ul>
        <div class="datagrid">
            <?php 
if (isset($_GET['C_rg']) || isset($_GET['C_registro'])) {
    if ($query = mysqli_query($com, $sql)) {
        $linhas = 1;
        $rows = mysqli_num_rows($query);
        if ($rows > 0) {
            echo "<table><thead><tr><th>Nome</th><th>Status</th><th>Nº Cartão</th><th>Dependentes</th></tr></thead>";
            while ($assoc = mysqli_fetch_assoc($query)) {
                echo "<tbody><tr><td>" . $assoc['nome'] . "</td><td>" . status($assoc['status']) . "</td><td>" . $assoc['registro'] . "</td><td>" . depedentes(0) . " dependente</td></tr></tbody>";
            }
            echo "</table><br></div>";
            echo "<h2> Dependentes</h2> <br>";
            getDep($_GET['C_rg']);
        } else {
            echo "Associado não encontrado";
        }
    }
}
mysqli_close($com);
?>
        </div>


        <div id="footer">
    </div>
    </form>
</div>