Mysql 查询 chrome 中的问题


Mysql query Issue in chrome

    <?php
session_start();
include("configdb.php");
if(!session_is_registered(username)){
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Projects</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function un_check(){
for (var i = 0; i < document.frmactive.elements.length; i++) {
var e = document.frmactive.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.frmactive.allbox.checked;
}
}
}
function Confirm(form){
alert("Project has been activated!");
form.submit();
}
function unConfirm(form){
alert("Project has been Deactivated!");
form.submit();
}
</script>
</head>
<body>
<div id="costDiv">
<div id="divErc"></div>
<div id="costBack">
<?php
if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE projects SET p_isActive = '".(isset($activate)?'1':'0')."' WHERE p_id IN $id";
$result = mysql_query($sql) or die(mysql_error());
}
?>
<?php include("hor_menu.php"); ?>

<form name="frmactive" method="post" action="">
<table width="350" border="0" cellspacing="1" cellpadding="5" align="center" style="margin-left:150px ; margin-right:auto ; margin-top:20px ; margin-bottom:auto ; position:absolute ; width:400px">
<tr>
<td align="center" ><input type="checkbox" name="allbox" onclick="un_check(this);" title="Select or Deselct ALL" style="background-color:#ccc;"/></td>
<td align="left"><strong>Project</strong></td>
<td align="left"><strong>Country</strong></td>
<td align="left"><strong>Active</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['p_id']; ?>"/></td>
<td><?php echo $rows['p_name']; ?></td>
<td><?php echo $rows['p_country']; ?></td>
<td><?php if ($rows['p_isActive'] == '1'){ echo'Active';} else{ echo 'Inactive';} ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5"><input name="activate" type="submit" id="activate" value="Activate" onClick="Confirm(this.form)" />
<input name="deactivate" type="submit" id="deactivate" value="Deactivate" onClick="unConfirm(this.form)"/></td>
</tr>
</table>

?>
</td>
</tr>
</table>
</form>
</body>
</html>

我有此代码。当我选中复选框项目时,将根据底部激活或停用。但是此代码在除谷歌浏览器和 Safari 之外的所有浏览器上都能完美运行。任何人都可以帮助 please.it 不断给出我的 SQL 语法错误,特别是在更新查询中的 where 子句之后。谢谢

如果您根据浏览器收到 SQL 错误,那么您很可能需要检查您的输入。PHP 的执行不会因您使用的浏览器而异,除了它从客户端控件(如文本框或触发器(获取的数据外。

我建议您以某种方式记录$sql变量,您可以尝试仅使用 var_dump ,以查看浏览器之间的数据如何变化。

这是

不合法的:id="checkbox[]"摆脱它。

没有必要为所有内容分配一个ID.仅当您在 javascript 中实际使用它时,才分配ID。否则就把它排除在外。

INPUT字段确实需要 name 属性,但这与 ID 完全不同。