0

I'm creating a table, each row has a button delete, which is supposed to delete the row. However, now, when I click delete, "nothing happens" and I have to refresh the page to see the results. Please Help.

My code index.php

<body>

    <?php include "include/connect.php"; ?>

    <table>
        <tr>
            <th>ID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Proffesion</th>
            <th>Rank</th>
            <th>Options</th>
            <th>&nbsp;</th>
        </tr>
        <tr>
            <form action="add.php" method="post">
                <td><input type="text" name="id" disabled size="5"></td>
                <td><input type="text" name="fname"></td>
                <td><input type="text" name="lname"></td>
                <td><input type="text" name="prof"></td>
                <td><input type="text" name="rank" size="5"></td>
                <td><input type="submit" value="add" name="watta"></td>
                <td>&nbsp;</td>
            </form>
        </tr>

        <?php
            $query = "SELECT * FROM staff";
            $vysledek = mysqli_query($link, $query);

            while ($udaj = mysqli_fetch_array($vysledek)):

                if($udaj[4]==0){
                    echo "<tr class='zero'>";
                } else {
                    echo "<tr>";    
                }



                echo "<td>" . $udaj[0] . "</td>";
                echo "<td>" . $udaj[1] . "</td>";
                echo "<td>" . $udaj[2] . "</td>";
                echo "<td>" . $udaj[3] . "</td>";
                echo "<td>" . $udaj[4] . "</td>";
                echo "<td class='btn'><a href=''>";

                ?>
                <form action="delete.php" method="get">
                    <input name="id" type="hidden" value="<?php echo $udaj[0]; ?>">
                    <input name="what" type="submit" value="DELETE">
                </form>

                <?php
                echo "</a></td>";
                echo "<td class='btn'><a href=''>edit</a></td>";

                echo "</tr>";

            endwhile;


        ?>

    </table>

</body>

delete.php

<?php

include "include/connect.php";

$toId = ($_GET["id"]);

$queryy = "DELETE FROM staff WHERE id=$toId";
$vysledek = mysqli_query($link, $queryy);

header('Location: http://www.w3dominik.com/x/phptest/');

connect.php

<?php

include "config.php";

$link = mysqli_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD, SQL_DBNAME);
mysqli_set_charset($link, "utf8");

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

Live demo at http://www.w3dominik.com/x/phptest/


ActiveRecord Association Type Mismatch

A bit more context. I'm using devise to create members. Upon signup i'd like a user to select an item from a database of itmes and have that item assoiciated with that member. so i can call item.members.new in the consol without the following assiciation error:

ActiveRecord::AssociationTypeMismatch: Carrier(#97584750) expected, got String(#83658370)

devise registrions/new view http://pastebin.com/KGnJQp2N

Members model http://pastebin.com/VmDbpSpY

carriers model http://pastebin.com/DPEV1NMd

carriers controller http://pastebin.com/uFfh9KrP

I'm convinced the error is in the following lines:

<div><%= f.label :carrier %><br />
<%= f.select :carrier, 
              options_for_select([["Select One", ""], *Carrier.all.map(&:name)]),
              :class => 'genForm_dropBox' %>
4

1 回答 1

0

查看 connect.php 并确保没有输出。 header()如果在它之前有任何空格或空行输出,则将不起作用。很容易错误地输入某种空白字符。 http://php.net/manual/en/function.header.php

于 2013-07-14T20:38:13.997 回答