已经尝试了几个小时,但我仍然无法找到我犯的错误。我已经插入并显示但没有更新。如果有人可以解决这个问题,那将是一个很大的帮助。这是我的代码:
updatetest.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update</title>
</head>
<body>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue)
;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}};
if(isset($_POST['update'])) {
$UpdateQuery = "UPDATE maklumat SET iC='$_POST[iC]', Name='$_POST[name]', IP='$_POST[ip]' WHERE iC= '$_POST[hidden]'";
mysql_query($UpdateQuery, $in2);
};
mysql_select_db($database_in2, $in2);
$query_in2 = "SELECT * FROM maklumat";
$Record = mysql_query($query_in2, $in2) or die(mysql_error());
$row_Record= mysql_fetch_assoc($Record);
$totalRows_Record= mysql_num_rows($Record);
?>
<form id="form1" name="form1" method="post" action="updatetest.php">
<p> </p>
<p> </p>
<center>
<table width="900" border="2">
<tr>
<th width="120"><div align="center">Identified Card</div></th>
<th width="191"><div align="center">Name</div></th>
<th width="12"><div align="center">IP Address</div></th>
<th width="121"><div align="center"> Action </div></th>
</tr>
<?php
do { ?>
<tr>
<td><div align="center"><?php echo "<input type=text name=iC value=" . $row_Record['iC']; ?> </div></td>
<td><div align="center"><?php echo "<input type=text name=name value=" .$row_Record['Name']; ?> </div></td>
<td><div align="center"><?php echo "<input type=text name=ip value=" .$row_Record['IP']; ?> </div></td>
<td><div align="center"><?php echo "<input type=hidden name=hidden value=" . $row_Record['iC']; ?> </div></td>
<td><div align="center"><?php echo "<input type=submit name=update value=update" ?> </div></td>
</tr>
<?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
</table>
<p> </p>
<p> </p>
</center>
<p> </p>
</form>
</body>
</html>
<?php
mysql_free_result($Record);
?>
答案 0 :(得分:1)
尝试以下:
<?php
$_POST = array("iC"=>"a", "name"=>"Does",'ip'=>'1.1.1.1', 'hidden'=>true);
$updateQuery = "UPDATE maklumat SET iC1='{$_POST['iC']}', Name='{$_POST['name']}', IP='{$_POST['ip']}' WHERE iC= '{$_POST['hidden']}'";
var_dump($updateQuery);
当你想从字符串中的数组中访问值时,你需要的是一对括号括号:{$ array ['key']}。
检查出来:Interpolation (double quoted string) of Associative Arrays in PHP
我认为您应该使用xdebug工具调试PHP文件,或者打印您的SQL语句。分析问题对您有所帮助。