我列出了一个表,其中包含来自MySQL的数据以及用于编辑或删除该行的操作。
这是上面图像的代码:
<table border="1" class="gridtable">
<th>Client Name</th>
<th>Category</th>
<th>Address</th>
<th>City</th>
<th>Contact Person</th>
<th>Contact Details</th>
<th>Sales Person</th>
<th colspan="2"></th>
<?php
$a=mysql_query("SELECT `clients`.`client-no`, `clients`.`client-name`, `clients`.`client-category`, `clients`.`client-address`, `clients`.`client-city`, `clients`.`client-contact-person`, `clients`.`client-contact-details`, `sales`.`firstname`, `sales`.`lastname`
FROM `clients`
INNER JOIN `sales`
ON `clients`.`sales-id`=`sales`.`sales-id`") or die(mysql_error());
if(mysql_num_rows($a)>0)
{
while($b=mysql_fetch_array($a))
{
echo"<tr><td>".$b['client-name']."</td><td>".$b['client-category']."</td><td>".$b['client-address']."</td><td>".$b['client-city']."</td><td>".$b['client-contact-person']."</td><td>".$b['client-contact-details']."</td><td>".$b['firstname'].' '.$b['lastname']."</td>"; ?>
<td>
<form action="#" method="post">
<input type="hidden" name="edit_client" value="<?php echo $b['client-no']; ?>" />
<input type="image" name="edit_client" value="<?php echo $b['client-no']; ?>" src="images/edit.png" onclick="javascript:editPopup()" title="Edit"/>
</form>
</td>
<td>
<form action="../deletefunction.php" method="post">
<input type="hidden" name="delete_client" value="<?php echo $b['client-no']; ?>" />
<input type="image" name="delete_client" value="<?php echo $b['client-no']; ?>" src="images/delete.png" onclick="return confirm('Are you sure you want to delete this item?')" title="Delete"/>
</form>
</td>
</tr>
<?php
}
}
else
{
?>
<tr><td colspan="6" style="text-align:center; color:#FF0000; font-size:16px;">*No Data Available!*</td></tr>
<?php
}
?>
</table>
<a href="javascript:addClient()" id="addclient"><img src="images/add.png" class="addicon" style=" display:inline;" /></a>
DELETE函数可以正常工作,但EDIT则不能。这是
<input type=image name=edit_client />
在其onclick
上调用的javascipt函数的代码:function editPopup()
{
var url = "../editfunction.php";
var width = 700;
var height = 600;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var windowFeatures = "width=" + width + ",height=" + height +
",status,resizable,left=" + left + ",top=" + top +
"screenX=" + left + ",screenY=" + top + ",scrollbars=yes";
window.open(url, "subWind", windowFeatures, "POS");
}
基本上,其作用是在监视器中心的新窗口中弹出
editfunction.php
。该页面应显示UPDATE页面,其中的数据来自$_POST[edit_client]
。但是,由于editfunction.php
错误,因此Notice: Undefined index: edit_client in C:\xampp\htdocs\isys\editfunction.php on line 12-yeah
似乎无法从第一页读取数据。这是它的代码:<?php
require("dbconnect.php");
echo $_POST['edit_client']."-yeah";
//edit client
if(isset($_POST['edit_client']) && !empty($_POST['edit_client']))
{
echo $_POST['edit_client']."-yeah";
//do the update here
}
?>
我究竟做错了什么?我该如何工作?谢谢。
PS:请不要介意
mysql_
的用法,请继续关注问题本身。 最佳答案
表单未提交。您正在启动活动,但未提交表单。您应将其用作删除按钮,并让图像按钮将表单提交到editfunction.php页面。