PHP提交按钮/结构?

时间:2016-06-05 19:59:47

标签: php

这里有一些我正在研究的代码。一切正常,我会输入我输入ID的部分,然后它会显示该ID行中的信息,还有2个弹出框,我可以在其中写入变量的新值。还有2个按钮,一个用于确认编辑已写入框,另一个用于从数据库中删除该行。

我仍然处于编程的基础知识,你可以看到并且在这部分代码中结构有问题吗?

任何人都可以帮助我让这两个提交按钮正常工作。

谢谢大家。 :)

if(isset($_POST['idnumber'])) {
$idnumber = protect($_POST['idnumber']);
global $idnumber;
if($idnumber == ""){
    echo "Please supply all fields!";
}
else{ 
    ?>
        <table cellpadding="2" cellspacing="2">
    <br />
    <tr>
        <td width="50px"><b>ID</b></td>
        <td width="150px"><b>Current name</b></td>
        <td width="200px"><b>Current description</b></td>
        <td width="100px"><b>Time added</b></td>
        <td width="100px"><b>Current status</b></td>
    </tr>
    <?php
        $get_tasks = mysqli_query($con, "SELECT id FROM task WHERE id='$idnumber'") or die(mysql_error());
        while($row = mysqli_fetch_assoc($get_tasks)){
        echo "<tr>";
        echo "<td>" . $row['id'] . "</td>";
        $get_taskname = mysqli_query($con, "SELECT taskname FROM task WHERE id='$idnumber'") or die(mysql_error());
        $task_name = mysqli_fetch_assoc($get_taskname);
        echo "<td>" . $task_name['taskname'] . "</td>"; 
        $get_description = mysqli_query($con, "SELECT description FROM task WHERE id='$idnumber'") or die(mysql_error());
        $description_text = mysqli_fetch_assoc($get_description);
        echo "<td>" . $description_text['description'] . "</td>";
        $get_dateadded = mysqli_query($con, "SELECT dateadded FROM task WHERE id='$idnumber'") or die(mysql_error());
        $date_added = mysqli_fetch_assoc($get_dateadded);
        echo "<td>" . $date_added['dateadded'] . "</td>";
        $get_status = mysqli_query($con, "SELECT status FROM task WHERE id='$idnumber'") or die(mysql_error());
        $cur_status = mysqli_fetch_assoc($get_status);
        if($cur_status['status'] == 1) {
            echo "<td>" . "Unfinished" . "</td>";
        }
        else{
            echo "<td>" . "Finished" . "</td>";
        }
        echo "</tr>";
        }

        if(isset($_POST['edittask'])) {
        $editname = protect($_POST['editname']);
        mysqli_query($con, "UPDATE task SET taskname=$editname WHERE id='$idnumber'") or die(mysql_error());
        }
        elseif(isset($_POST['deletetask'])) {
        mysqli_query($con, "DELETE FROM task WHERE id='$idnumber'") or die(mysql_error());
        }
        ?>     
    <form action="test2.php" method="POST" >
        <td width="50px"><b></b></td>
        <td width="150px"><b>New name: <input type="text" name="editname"/></b></td>
        <td width="200px"><b>New desc: <input type="text" name="editdesc"/></b></td>
        <td width="100px"><b></b></td>
        <td width="100px"><b>D</b></td>

    <input type="submit" name="edittask" value="Edit task"/> <br />
    <input type="submit" name="deletetask" value="Delete task"/> <br />
    </form>

    <?php
    }
}     
        ?>
</table>
<br /><br />
<form action="test2.php" method="POST" >
Insert ID of task to edit: <input type="text" name="idnumber"/>
<input type="submit" name="ids" value="Find task"/> <br />
</form>

0 个答案:

没有答案