galep
galep

Reputation: 80

works fine in WAMP but doesn't work in XAMPP

I have the following code in my program that works perfectly with the WAMP server. But I had to change the WAMP server for XAMPP and I don’t know why it doesn’t execute some parts of the code. There’s also no error message.

The problem is that in the table code <table>, it doesn’t show after the third <tr> or when the 'Toggle' starts. It also doesn’t show the submit button.

I don’t understand why everything works correctly in WAMP but not in XAMPP. Can someone help me see why it fails? Thank you

Project.php

<?php
include_once("Conexion.php");
include_once("functions.php");
ob_start();

$_SESSION['ex_time'] = date('Y-m-d H:i:s');
$list_ex = array();
$result = doSearch($conn);
?>

    <!DOCTYPE html>
    <html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="styleProject.css">
</head>

<body>

<div id="centered_A">

    <form action='' method='post'>
    <table id="exercises">
        <tr>
            <th colspan="3"><h2>Exercises</h2></th>
        </tr>
        <tr>
            <th><h3>Exercise_ID</h3></th>
            <th><h3>Title</h3></th>
            <th><h3>Difficulty
                <form id="difficulty_form" method="get">
                    <select id="filter" name="filter" onchange="document.getElementById('difficulty_form').submit()">
                        <option value="All">Todas</option>
                        <?php
                        for ($i = 1; $i <= 5; $i++) {
                            $selected = '';
                            if (isset($_GET['filter']) && $_GET['filter'] == $i) {
                                $selected = ' selected';
                            }
                            echo "<option value=\"$i\"$selected>$i</option>\n";
                        }
                        ?>
                    </select>
                </form>
                </h3></th>
        </tr>

        <?php
        $order = 1;
        $num_ex = 1;
        while($row = $result->fetch_assoc())
        {
            array_push($list_ex, $row["exercise_id"]);

            $sql_check_ex = "select * from answers a where a.student_id=".$_SESSION['user_id']." and a.exercise_id_fk=".$row["exercise_id"].";";
            $result_check_ex = $conn->query($sql_check_ex);
                    ?>

                    <tr>
                        <td><?php echo $num_ex; ?></td> 
                        <!---Click Toggle Exercise-->
                        <td><a  onclick="myFunction(<?php echo $row["exercise_id"] ?>)" role="button" class="btn" target="_blank" ><?php echo $row["title"]; ?></a>
                            </td>
                        <td><?php echo $row["difficulty"]; ?></td>
                    </tr>
            <!--- Toggle --->
            <tr id="toggle<?php echo $row["exercise_id"] ?>"  style="display:none">
                <td colspan="3">

                        <?php
                        $sql = "SELECT * FROM exercises WHERE exercise_id='".$row["exercise_id"]."'";
                        $result_ej = $conn->query($sql);
                        $row_ej = $result_ej->fetch_assoc();
                        ?>

                        <p><?php $row["exercise_id"] ?> <?php echo $row["text"]?></p>
                        <br><!--- Radio Button --->
                        <?php
                        if ($row["type"] == 0) {

                            $ansarray = explode("\n", $row["image_path"]);
                            $randomans = [];
                            for($i=0; $i<count($ansarray); $i++) {
                                $a = array($i+1, $ansarray[$i]);
                                array_push($randomans, $a);
                            }
                            shuffle($randomans);
                            for($i=0; $i<count($randomans); $i++) {
                                echo "<div class=\"radio\" style=\"text-align:left; display:flex; vertical-align: baseline;\">";
                                echo "<input type=\"radio\" style=\"margin-top: 8px; cursor:pointer;\" name=\"choice".$row["exercise_id"]."\" value= \"".$randomans[$i][0]."\"  />".$randomans[$i][1]."<br>";
                                echo "</div>";
                            }

                            echo "<input type=\"text\" name=\"choicetext".$row["exercise_id"]."\" value='multi' style=\"display:none;\">";

                        } else {
                            ?>
                            <input type="radio"  style="margin-top: 8px" name="choice<?php echo $row["exercise_id"] ?>" value= "0" checked="checked" style="display:none;" />

                            <?php
                        }
                        ?>
                        <br>
                        <!--- Select level --->
                        <p2>Select difficulty level:</p2>

                        <select name="choose<?php echo $row["exercise_id"] ?>" id="choose<?php echo $row["exercise_id"] ?>">>
                            <option value="1" <?php if($row["difficulty"]=="1") { echo "selected"; } ?> >1</option>
                            <option value="2" <?php if($row["difficulty"]=="2") { echo "selected"; } ?> >2</option>
                        </select>
             </td>
             </tr><!---Finish Toggle --->


                <?php

            $order++;
            $num_ex++;
        }
        ?>

    </table>
    <br><!---Submit Button-->
    <input class="buttonSubmit" type="submit" name="submit_proj_ex" value="Submit">
    </form>

    <script>
        function myFunction(ejer_id) {
            var x = document.getElementById("toggle" + ejer_id);
            if (x.style.display === "none") {
                x.style.display = "table-row";
            } else {
                x.style.display = "none";
            }
        }
    </script>

</div>
</body>

<?php
if (isset($_POST['submit_proj_ex'])) {
    include_once("store_answers.php");
    header('location: Results.php');
}
?>
</html>

functions.php

<?php
function doSearch($conn, $fields = "*") {
    $sql = "SELECT $fields FROM exercises, ex_tag, tags where exercise_id = exercise_id_fk and tag_id = tag_id_fk";

    if (isset($_GET['filter']) && $_GET['filter'] !== 'All') {
        $filter = (int) trim($_GET['filter']);
        $sql .=  " and exercises.difficulty = '$filter'";
    }

    if (!empty($_SESSION['tags_array'])) {
        $sql .= " and (";
        foreach ($_SESSION['tags_array'] as $tagId)
            $sql .= 'tag_id = ' . $tagId . ' or ';

        $sql .= "tag_id = -1)";
    }
    $sql .= ' group by exercise_id_fk';
    return $conn->query($sql);
}
?>

Upvotes: 2

Views: 374

Answers (1)

Elroy Jetson
Elroy Jetson

Reputation: 968

Run phpinfo() in both WAMP and XAMP. I'm not certain what your issue is, but if it works in one and not the other, perhaps they are using different versions of php. If this is the case, you will need to use the same version of php in your XAMP as you were using in WAMP, or go through your code and try to figure out how to convert your code, such that it works correctly with the version on your XAMP. The former is probably the path of least resistance.

Upvotes: 1

Related Questions