Sunda Cyber Army


* Sunda Cyber Army 2k17 *
Indonesia Defacer ~


Path : /home/dent/public_html/exams/vikram/
File Upload :
Current File : /home/dent/public_html/exams/vikram/results.php

<?php
// disclosure: I used $row command to make it simpler, I am aware we have not used it in class - also used snippets from my previous assignments to make this work
if (empty($_REQUEST['manufacturer_id']) OR empty($_REQUEST['system_id']) OR empty($_REQUEST['type_id'])) {
    echo "Please go through search page. (or redirect)";
    exit();
}

$host   = "webdev.iyaserver.com";
$userid = "dent_test";
$userpw = "Acad276_Ttrojan_Dev2Ex@m";
$db     = "dent_exam";

$mysql = new mysqli($host, $userid, $userpw, $db);
if ($mysql->connect_errno) {
    echo "db connection error : " . $mysql->connect_error;
    exit();
}

$sql  = "SELECT d.device_id, d.name, d.price, m.manufacturer, o.system, t.type ";
$sql .= "FROM device d ";
$sql .= "JOIN make m       ON d.manufacturer_id = m.manufacturer_id ";
$sql .= "JOIN os o         ON d.system_id       = o.system_id ";
$sql .= "JOIN devicetype t ON d.type_id         = t.type_id ";
$sql .= "WHERE 1=1 ";

if (!empty($_REQUEST['device_name'])) {
    $sql .= " AND d.name LIKE '%" . $_REQUEST['device_name'] . "%'";
}

if ($_REQUEST['manufacturer_id'] != "all") {
    $sql .= " AND d.manufacturer_id = " . (int)$_REQUEST['manufacturer_id'];
}
if ($_REQUEST['system_id'] != "all") {
    $sql .= " AND d.system_id = " . (int)$_REQUEST['system_id'];
}
if ($_REQUEST['type_id'] != "all") {
    $sql .= " AND d.type_id = " . (int)$_REQUEST['type_id'];
}

$sql .= " ORDER BY d.name";

$results = $mysql->query($sql);
if (!$results) {
    echo "<hr>Your SQL:<br> " . $sql . "<br><br>";
    echo "SQL Error: " . $mysql->error . "<hr>";
    exit();
}
?>

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title>Acad276 Practical Exam: Results</title>

    <style>

        .container {

    width:  600px;

            margin: auto;

        }

        h1 {

    margin: auto;

    text-align: center;

            background-color:   #900;

            color:  #FC0;

            height: 60px;

            line-height: 60px;

        }

        .num-results {

    margin: 20px 10px;

        }

        table {

    margin: auto;

    margin-bottom: 20px;

            width:  80%;

            border-collapse: collapse;

        }

        th, td {

    border: 1px solid #900;

            border-collapse: collapse;

            padding:    10px;

            text-align: center;

        }

        img {

    width: 100px;

        }

        .nav-link{

    margin: 10px 0px;

            font-size: 14px;

        }

    </style>

</head>

<body>
<div class="container">
    <h1>Mobile Device Database: Search Results</h1>

    <div class="nav-link">
        <a href="search.php"><< Back to Search Page</a><br><br>
    </div>

    <div class="num-results">
        Your search returned <strong><?php echo $results->num_rows; ?></strong> result(s).
    </div>

    <table>
        <tr>
            <th>Name</th>
            <th>Price</th>
            <th>Manufacturer</th>
            <th>System</th>
            <th>Type</th>
        </tr>

        <?php
        while ($row = $results->fetch_assoc()) {
            ?>
            <tr>
                <td><a href="details.php?id=<?php echo $row['device_id']; ?>"><?php echo $row['name']; ?></a></td>
                <td><?php echo $row['price']; ?></td>
                <td><?php echo $row['manufacturer']; ?></td>
                <td><?php echo $row['system']; ?></td>
                <td><?php echo $row['type']; ?></td>
            </tr>
            <?php
        }
        ?>
    </table>
</div>

</body>