用PHP显示MYSQL。想要将选定的行移动到另一个sql表并从现有表中删除

时间:2012-04-11 16:58:58

标签: php mysql html

我正在为我的部门设计一个移动服务台系统。我目前有一个HTML表单,将数据提交到MySQL表。然后,我将该表显示在单独的页面上,每行旁边都有复选框。目前,完整按钮被编码为简单地删除任何已检查的记录。但是,按此按钮似乎什么都不做。我想知道我做错了什么。

以下是代码:

<?php
$host="localhost";
$username="root";
$password="";
$db_name="opentix";
$tbl_name="opentix";

//Connect and Select
mysql_connect("$host","$username","$password") or die("Cannot Connect");
mysql_select_db("$db_name")or die("Cannot Select Database");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>

<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td><form name="OpenTickets" method="post" action"">
<table width="400" border="0" cellspacing="3" cellpadding="0" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"></td>
<td align="center" colspan="15" bgcolor="#FFFFFF"><strong>Open Tickets</strong>
</td>
</tr>
<tr>
    <td align="center" bgcolor="#FFFFFF"><strong></stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Ticket Number</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Time Created</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Room</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>If Other</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Problem Type</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Machine Name</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Operating System</stong></td>  
    <td align="center" bgcolor="#FFFFFF"><strong>Problem Description</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Troubleshooting</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Request</stong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>Email</stong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
    ?>
<tr>
    <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['tixnum']; ?>".</td>
    <td bgcolor="#FFFFFF"><? echo $rows['tixnum']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['timecreated']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Room']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Other']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Type']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Name']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['System']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Problem']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Troubleshooting']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Request']; ?></td>
    <td bgcolor="#FFFFFF"><? echo $rows['Email']; ?></td>
</tr>
<?php
}
?>
<tr>
    <td colspan="15" align="center" bgcolor="#FFFFFF"><input name="complete" type ="submit" id="complete" value="Complete"></td>
</tr>
<?php
    if($complete){
        for($i=0;$i<$count;$i++){
            $del_id = $checkbox[$i];
            $sql = "DELETE FROM opentix WHERE id='$del_id'";
            $result = mysql_querry($sql);
        }
if($result){
    echo"<meta http-equiv=\"refresh\"content=\"0;URL=pcsehelpdesk\completeopen.php\">";
}
}
mysql_close();
?>

</table>
</form>
</td>
</tr>
</table>

对我做错的任何输入都会很棒。

1 个答案:

答案 0 :(得分:0)

看起来你需要告诉表单发布给自己。将其添加到您的代码中:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>"

更多阅读:http://tycoontalk.freelancer.com/php-forum/51903-php-self-submitting-form.html