如何将$ row ['value']返回到pollUpdate.php中的可编辑值字段

时间:2016-09-09 15:17:52

标签: php mysql

目前,$ row ['value']返回到pollUpdate.php中的值字段,该字段不可编辑。如何使该字段可编辑,并以dB为单位更新值字段。我试图将ID = $ row ['name']和value = $ row ['value']传递给updatedPoll.php。这些值虽未在网址中传递。

html>
        <body>
            <a href="poll.html">Poll</a>
            <?php
            $connection = mysqli_connect("localhost", "root", "");
            mysqli_select_db($connection, "ukelection2015");
            $rs = mysqli_query($connection, "select * from poll");
            ?>
            <hr>
            <table border=1>
                <tr>
                    <th>Name</th>
                    <th>Value</th>
                    <th>Color</th>
                    <th></th>
                </tr>
                <?php
                while ($row = mysqli_fetch_array($rs)) {
                    print("<form method= 'post' action= ''>");
                    for ($x = 0; $x <= 2; $x++) {
                        if ($x == 0) {
                            print("<tr>");
                        } else {
                            /*   print("<td>" . $row['name'] . "</td>" . "<td><input  vtype = 'hidden' name= 'input'  value=>".$row['value']."</input></td>" . "<td>" . $row['color'] . "</td>"."<td><a name = 'ID' href='updatePoll.php?ID=".$row['name']."'>Update</a></td>"); */
                               print("<td>" . $row['name'] . "</td>" . "<td><input  type = 'hidden' name= 'input'   value = '".$row['name']."' >".$row['value']."</></td>" . "<td>" . $row['color'] . "</td>"."<td><a name = 'ID' href='updatePoll.php?ID=".$row['name']."+ &value=".$row['value']."'>Update</a></td>"); 
                          /*  print("<td>" . $row['name'] . "</td>" . "<td><input  type = 'hidden' name= 'input'   value = '" . $row['name'] . "' >" . $row['value'] . "</></td>" . "<td>" . $row['color'] . "</td>" . "<td><a name = 'ID' href='updatePoll.php?ID=" . $row['name']."'>Update</a></td>"); */
                              /*  print("<td>" . $row['name'] . "</td>" ."<td><input type = 'hidden' name= 'input'   value = '" . $row['value'] . "'>".$row['value']."</></td><a  name='ID' href ='updatePoll.php?ID=" . $row['name'] . "'>" . $row['name'] . "</a></td>"); */


                            $x++;
                            if ($x == 1) {
                                print "</tr>";
                            }
                        }
                    }
                    print("</form>");
                    // this hidden field is used in updatePoll.php to get the party name to update (i.e. $name=$_POST['name'];)
                    /*  print("<input type='hidden' name ='name' value={$row['name']}>"); */

                    /*   print("<tr>"); */

                    // name
                    // value
                    // color

                    /*  print("<td><input type=\"submit\" value=\"Update\"/></td>"); */
                    /*   print("</tr>"); */
                    /*  print("</form>"); */
                }
                mysqli_close($connection);
                ?>

            </table>
        </body>
    </html

>
<?php

//update the party value with the data posted here
$connection = mysqli_connect("localhost","root","");
mysqli_select_db($connection,"ukelection2015");

$name=$_POST['name'];
$value=$_POST['value'];

//$value=...

  $sql = " UPDATE `poll` SET `value`='".$value."' WHERE `name`='" . $name . "'";
            $result = mysqli_query($connection, $sql);
mysqli_close($connection);

// redirect to pollUpdate.php
header("Location: pollUpdate.php");
?>

0 个答案:

没有答案