我尝试编辑/更新我的数据表单但是当我点击"编辑"按钮它没有改变任何东西,我不知道究竟发生了什么,输出说
致命错误:未捕获错误:在null上调用成员函数query() 在C:\ xampp \ htdocs \ Admin \ requestform5.php:24堆栈跟踪:#0 {main} 在第24行的C:\ xampp \ htdocs \ Admin \ requestform5.php中抛出
编码
<?php
include "errorReporting.php";
include "conn.php";
$conn = connect();
$db = connectdb();
$wardID = $_REQUEST["wardID"];
$RequestName = $_REQUEST["RequestName"];
$Department =$_REQUEST["Department"];
$Position =$_REQUEST["Position"];
$Date=$_REQUEST["Date"];
$TypeOfRequest=$_REQUEST["TypeOfRequest"];
$PleaseSpecify=$_REQUEST["PleaseSpecify"];
$DateRequire= $_REQUEST["DateRequire"];
$DateReturn= $_REQUEST["DateReturn"];
mysqli_select_db ($conn,"admin") or die ($conn->error ."\n");
$query = "select*from requestform";
$result= $conn->query($query) or die ($conn->error."\n");
$row_result =mysqli_fetch_assoc($result);
mysqli_select_db ($conn,"admin") or die ($conn->error."\n");
$mysqli->query( "UPDATE requestform SET RequestName='$RequestName',Department='$Department',Position='$Position',Date='$Date',TypeOfRequest='$TypeOfRequest',PleaseSpecify='$PleaseSpecify',DateRequire='$DateRequire',DateReturn='$DateReturn' where wardID='$wardID'");
$mysqli->affected_rows or die ($conn->error()."\n");
header("Location:requestform3.php");?>
答案 0 :(得分:1)
您的查询是主要问题
$query = "select*from requestform";
更改为
mysqli_select_db ($conn,"admin") or die ($conn->error ."\n");
$query = "select * from requestform";
$result= $conn->query($query) or die ($conn->error."\n");
$row_result =mysqli_fetch_assoc($result);
$conn->query( "UPDATE requestform SET RequestName='$RequestName',Department='$Department',Position='$Position',Date='$Date',TypeOfRequest='$TypeOfRequest',PleaseSpecify='$PleaseSpecify',DateRequire='$DateRequire',DateReturn='$DateReturn' where wardID='$wardID'");
$conn->affected_rows or die ($conn->error()."\n");
答案 1 :(得分:0)
问题在于第24行
$ mysqli-&gt;查询(&#34; UPDATE requestform SET RequestName =&#39; $ RequestName&#39;,Department =&#39; $ Department&#39;,Position = &#39; $位置&#39;,日期=&#39; $日期&#39;,TypeOfRequest =&#39; $ TypeOfRequest&#39;,PleaseSpecify =&#39; $ PleaseSpecify&#39;,DateRequire =&# 39; $ DateRequire&#39;,DateReturn =&#39; $ DateReturn&#39; where wardID =&#39; $ wardID&#39;&#34;); $ mysqli-&gt; affected_rows 或死亡($ conn-&gt;错误()。&#34; \ n&#34;);
这个$ mysqli来自哪里?这是一个对象吗?我无法在任何地方看到这个对象。你有$ conn对象。
只需将$ mysqli-&gt;查询更改为$ conn-&gt;查询