PHP:HTML隐藏输入值在查询mysql时生成错误
我正在制作一个网页,允许用户编辑他们的汽车信息。在主线中,有一个编辑按钮(带有隐藏键值的输入类型文本),它将用户带到这个“编辑汽车信息”页面。最初,第一次打开页面后,此隐藏值用于查询数据库、检索原始信息并将其设置为字段的占位符。用户可以在输入字段中写入信息,然后按下“提交编辑”按钮,然后更新数据库表中的行。但是,我得到一个错误,即隐藏值的名称未定义。我不明白,当更新查询在select查询中运行正常时,它怎么可以不被定义。有人能解释一下吗?我该怎么办?这是错误的图片: 这是主着陆代码:(此处设置隐藏值)PHP:HTML隐藏输入值在查询mysql时生成错误,php,html,mysql,html-input,Php,Html,Mysql,Html Input,我正在制作一个网页,允许用户编辑他们的汽车信息。在主线中,有一个编辑按钮(带有隐藏键值的输入类型文本),它将用户带到这个“编辑汽车信息”页面。最初,第一次打开页面后,此隐藏值用于查询数据库、检索原始信息并将其设置为字段的占位符。用户可以在输入字段中写入信息,然后按下“提交编辑”按钮,然后更新数据库表中的行。但是,我得到一个错误,即隐藏值的名称未定义。我不明白,当更新查询在select查询中运行正常时,它怎么可以不被定义。有人能解释一下吗?我该怎么办?这是错误的图片: 这是主着陆代码:(此处设置
汽车登记:用户的主起落架
帐户信息
轮廓
登记车辆
您只能编辑以下信息:
车辆类型:
这就是为什么要关闭while循环
while ($temp = $result->fetch_assoc()){
?>
这里也是
<?php
}
“>
您没有发送id
,这是因为出现错误。请先使用此代码检查id
是否存在:
$plate_no='';
$car_type = '';
if(isset($_POST["id"])){
$plate_no= $_POST["id"]; //This line causes an error
$_SESSION['plateNo'] = $plate_no;
$query= "select * from cars where Plate_no='".$plate_no."'";
$result = $mysqli->query($query);
while( $row = $result->fetch_assoc()){
$plate_no = $row['Plate_no'];
$car_type = $row['Car_type'];
}
}
不发布文本图片$plate\u no=$\u post[“id”];//此行导致错误
错误是什么?错误在我链接的图片中。它是一个“未定义的索引:id”“在第27行,我可以用html打印表格,而不是在php代码中回显html。我这样做很好,但你还是同意我的建议!我会试试这个,让你知道它是怎么回事。如果没有设置id,我应该采取什么措施?我试着把车牌号作为一个会话变量发送。这是你的决定,你可以验证这一点,并要求它,或者做其他事情
while ($temp = $result->fetch_assoc()){
?>
<?php
}
print"<h3> Registered Cars </h3>
<div class='container2'>";
$username="root";
$password="";
$database="Car_registration";
$mysqli= new mysqli("localhost",$username,$password,$database);
$query= "select * from cars where license_no='".$license_no."'";
$result = $mysqli->query($query);
echo "<table border=1>
<tr>
<th>Plate No.</th>
<th>License No.</th>
<th>Car Type</th>
<th>Fines</th>
<th>City</th>
<th>Edit</th>
<th>Delete</th>
</tr>";
while ($temp = $result->fetch_assoc())
{
print"
<tr>
<td><?php echo $temp['Plate_no']; ?></td>
<td><?php echo $temp['license_no']; ?></td>
<td><?php echo $temp['Car_type']; ?></td>
<td><?php echo $temp['Fines']; ?></td>
<td><?php echo $temp['city']; ?></td>
<td>
<form action = "edit_car.php" method="post">
<input type="hidden" name="id" value="<?php echo $temp['Plate_no']; ?>">
<input type="submit" name="edit" value="Edit">
</form>
</td>
<td>
<form action = "delete_car.php" method="post">
<input type="hidden" name="id" value="<?php echo $temp['Plate_no']; ?>">
<input type="submit" name="delete" value="Delete">
</form>
</td>
</tr> ";
}
print"</table>
</div>";
$plate_no='';
$car_type = '';
if(isset($_POST["id"])){
$plate_no= $_POST["id"]; //This line causes an error
$_SESSION['plateNo'] = $plate_no;
$query= "select * from cars where Plate_no='".$plate_no."'";
$result = $mysqli->query($query);
while( $row = $result->fetch_assoc()){
$plate_no = $row['Plate_no'];
$car_type = $row['Car_type'];
}
}