您好我正在尝试从 HTML 表单更新单个字段,由于某种原因,我传递给更新查询的会话变量之一未被接受。我已经在页面中回显了该变量,因此相当确定它存在于内存中。
注意,我知道我的代码非常不安全,但我正在学习 PHP,一旦我掌握了基础知识,我会检查它并使其达到最佳实践标准。
E2A:如果我做 var_dump($filename); 在尝试运行查询之前它返回 string(6) "356/18",在查询之后它返回 NULL。我没有在任何地方取消设置变量,所以它会去哪里!
这是我的表格:
<form method="post" action="">
<p>Your username is: <?php echo $_SESSION['userid'] ?> Your company ID is: <?php echo $companyid['id']?></p>
<h3>Please enter note for file: <?php echo $filename; ?></h3>
<table width="200" cellpadding="5">
<tr>
<th width="18%" align="right" nowrap>Add Note: </th>
<td width="82%" nowrap>
<input type="text" name="note" />
</td>
</tr>
<tr>
<td colspan="2" width="100%" nowrap>
<input type="submit" value="Submit" name="Submit" />
</td>
</tr>
</table>
</form>
这是我的更新查询:
$sql = "UPDATE fields SET Notes = ('".mysql_real_escape_string(stripslashes($_REQUEST['note']))."')
WHERE companyId='".$companyid['id']."' AND fileNumber ='".$filename."'";
if($result = mysql_query($sql)) {
echo "<h1>Thank you</h1>Your information has been entered into our database<br><br>";
echo $sql;
echo $filename;
} else {
echo "ERROR: ".mysql_error();
}
} else {
回显 $sql 会产生以下结果:
UPDATE fields SET Notes = ('asdasda') WHERE companyId='11' AND fileNumber =''
这是我实例化 POST 变量的地方。
include "header.php";
$checkFiles = "checkFiles.php";
// Catches form input from previous page and stores it into session variable called filename for future reference;
$_SESSION['filename']=$_POST['filename'];
$filename = $_SESSION['filename'];
//User id stuff from previous page too;
$userid = $_SESSION['userid'];
$id = mysql_query("SELECT id FROM users WHERE DXNumber='".$userid."'");
// Returns pointer so fetch it as an array and insert it into variable $companyid for later use;
$companyid = mysql_fetch_array($id);