dtds8802 2013-10-15 13:34
浏览 37

从表单更新SQL

I would like some input, how do I execute the update query from the form in my code I am sure I have it in the wrong place I dont get any errors but it does not update I believe it where its at in the code ? I think I will need a loop to catch the updates to text boxes..right ? Is there a better way that I should be looking at this? I was going to send the update to a new page but thought it would be better to keep it in one page so you see where I REM the submit ' code. How does the phpmyadmin update the text box? I assume they use java script would that be better? Any constructive input would be appreciated.

            <html>
            <?php
            session_start();
            ?>
            <head>

            <basefont face="Arial">
            <title>Search</title>
            </head>

            <body>
                  <?php

            // include the page Header

            include('header.php');

            ?>

            <?php
            $today = date("n/j/Y");

             // set database server access variables:

            $host = "localhost";
            $user = "test";
            $pass = "test";
            $db = "test";

            // open connection

            $connection = mysqli_connect($host, $user, $pass, $db); 
            if (mysqli_connect_errno($connection)) {
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }
            // create query
            $query = "SELECT * FROM testingqa1160";
            $result = mysqli_query($connection, $query);

            $subbox = '<input type="Submit" value="Update" name="Submit">';
             // echo '<form name="release" action="somepage.php" method="get">';
            if (mysqli_num_rows($result) > 0) {

                // print them one after another
                echo "<center>"; 
                echo "<center><FONT SIZE=18>";
                echo "   Material  to be tested  </font>";
                echo "</center>";


                echo "<center><table cellpadding=1 border=1>";
                   //echo "<tr>";
                    echo "<center>";
                    echo "<td><center>"."ID"."</center></td>";
                    echo "<td><center>"."Material"."</center></td>";
                    echo "<td><center>"."Test"."</center></td>";
                    echo "<td><center>"."Sample"."</center></td>";
                    echo "<td><center>"."Freq"."</center></td>";
                    echo "<td><center>"."STP"."</center></td>";
                    echo "<td><center>"."Release"."</center></td>";
                    echo "<td><center>"."Notes"."</center></td>";
                    echo "<td><center>"."LSL"."</center></td>";
                    echo "<td><center>"."USL"."</center></td>";
                    echo "<td><center>"."Lot"."</center></td>";
                    echo "<td><center>"."Results"."</center></td>";
                    echo "<td><center>"."Release"."</center></td>";
                    echo "<td><center>"."Date"."</center></td>";
                    echo "</center></tr>";

                while($row = mysqli_fetch_row($result)) {

                    echo "<tr>";
                    $lottxtbox ='<input type="text" name="'.$row[0].'lotbox"size="6" value="'.$row[11].'">';
                    $restxtbox ='<input type="text" name="'.$row[0].'resbox" size="4" value="'.$row[12].'">';
                    $chbox = '<input type="checkbox" name="'.$row[0].'checkbox">';

                    echo "<td>".$row[0]."</td>";
                    // echo "<td>".$row[1]."</td>";
                    echo "<td><center>".$row[2]."</center></td>";
                    echo "<td><center>".$row[3]."</center></td>";
                    echo "<td><center>".$row[4]."</center></td>";
                    echo "<td><center>".$row[5]."</center></td>";
                    echo "<td><center>".$row[6]."</center></td>";
                    echo "<td><center>".$row[7]."</center></td>";
                    echo "<td><center>".$row[8]."</center></td>";
                    echo "<td><center>".$row[10]."</center></td>";
                    echo "<td><center>".$row[9]."</center></td>";
                    echo "<td><center>".$lottxtbox."</center></td>";
                    echo "<td><center>".$restxtbox."</center></td>";
                    echo "<td><center>".$chbox."</center></td>";
                    echo "<td>".$today."</td>";
                    // echo "<td>".$row[12]."</td>";
                    // echo "<td>".$row[13]."</td>";
                            echo "</tr>";

                }

                echo "</table></center>";


            echo "</center>";
            echo "<td><center>".$subbox."</center></td>";
            echo "</form>";



            }

            else {

                // no

                // print status message
            echo "<center><FONT SIZE=18>";
            echo $_GET["mnumber"];
                echo "   Material is not found! </font>";
                echo "</center>";

            }

            // free result set memory

            mysqli_free_result($result);

            // close connection

            mysqli_close($connection);
            ?>

            <?php
            if(isset($_POST['Submit'])){//if the submit button is clicked
            $update = $_POST['.$row[0]."lotbox"'];
            $query="UPDATE Lot = $update where trace = '".$row[0]."'";
            mysqli_query($connection,$query);
            }
            ?>

                  <?php

            // include the page footer

            include('footer.php');

            ?>
            </body>

            </html>
  • 写回答

1条回答 默认 最新

  • douchun3680 2013-10-15 14:51
    关注

    You are closing the connection but afterwards you still use the update query + your update query is wrong. Take a look at this for update query (You forgot the SET:

    update query

    UPDATE table_name
    SET column1=value, column2=value2,...
    WHERE some_column=some_value
    

    Why are you doing this?:

                mysqli_close($connection);
            ?>
    
            <?php
            if(isset($_POST['Submit'])){//if the submit button is clicked
    

    Closing the PHP tags and immediatly open it again. Why?

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题