dqzve68846 2012-05-31 08:34
浏览 95
已采纳

php如何在表中添加编辑按钮并加载数据以编辑表单

what i am trying to do: loading data from mysql database in a table with edit buttons.

what is going wrong: when clicking on edit buttons it doesn't load the data on the edit form.

what i have tried: i tried the following code at home on Firefox and it worked perfectly. but at work it fails to load the data in Firefox in the edit form and in IE clicking the button does nothing.

<?php
echo '<table id="viewAll">';
            echo '<tr>';
            echo '<th>Product</th>';
            echo '<th>Status</th>';
            echo '<th>Summary</th>';
            echo '<th>Created</th>';
            echo '<th>Updated</th>';
            echo '<th>Edit</th>';

            echo '</tr>';


            while ($data=mysqli_fetch_array($result)){

            echo '<tr align="center">

            <td>'.$data['product'].'</td>
            <td>'.$data['status'].'</td>
            <td align="left">'.$data['summary'].'</td>
            <td>'.$data['created'].'</td>
            <td >'.$data['updated'].'</td>';

            echo "<td><a href=\"editForm.php?id=$data[id]\" style=\"text-decoration: none\"><input type=\"submit\" value=\"Edit\" /></a></td>";

            echo '</tr>';


                }#end of while


            }#end of if



echo '</table>';
?>

and then i do:

$id=$_GET['id'];



            $query="SELECT * FROM tickets WHERE id='$id'";


            $result = mysqli_query($db,$query) or die( "My query ($query) generated an error: ".mysql_error());

            $data=mysqli_fetch_array($result);





            mysqli_close($db);

I use the contents in the data array to load it into the field in the edit form..

unfortunately this doesn't work in IE. clicking edit button doesn't do anything. Can somebody please tell me how to fix it? Thanks.

  • 写回答

5条回答 默认 最新

  • douniao7308 2012-05-31 09:12
    关注

    Try using this:

    echo "<td><form action=\"editForm.php\" method=\"get\"><input type=\"hidden\" name=\"id\" value=\"$data['id']\" style=\"text-decoration: none\" /><input type=\"submit\" value=\"Edit\" /></form></td>";
    

    That will mean you can still use a button.

    Also, I strongly suggest if you are not using tables for tabular data, find an alternative, such as <div>s.

    And remember to sanitise your SQL queries, or you may be susceptible to SQL injection attacks. (e.g. $id=$_GET['id']; => $id=mysqli_real_escape_string($conn, $_GET['id']); where $conn is your MySQL connection object).

    You can search for any of these things on Google.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料