gpt4 book ai didi

php - 无法从 phpmyadmin 回显数据

转载 作者:行者123 更新时间:2023-11-29 06:57:47 25 4
gpt4 key购买 nike

Am 已经创建了这样的表单并且工作完美,但在最后两个表单不工作时,它显示警告 - undefined variable :reg_no 和 cost。我试图按照以前的形式遵循算法,但没有任何反应。我的目标是更新插入的数据,这是我的表单

<!doctype html>
<html>
<head>

<meta charset="utf-8">
<title>Edit invoice</title>
<link rel="stylesheet" href="box_style.css" />
</head>

<body>

<?php

include ("db_con.php");

if(isset($_GET['edit_invoice'])){

$edit_i_id = $_GET['edit_invoice'];

$select_invoice = "select * from invoice where i_id='$edit_i_id'";

$run_query = mysqli_query($con, $select_invoice);

while ($row_invoice=mysqli_fetch_array($run_query)){

$i_id = $row_invoice['i_id'];
$reg_no = $row_invoice['reg_no'];
$cost = $row_invoice['cost'];

}
}

?>

<div class='form'>
<form action="" method="post" enctype="multipart/form-data" >

<table width="745" align="center" border="2">


<p style="text-align: center;"><strong><span style="text-decoration: underline;">EDIT INVOICE:</span></strong></p>

<tr>
<td align="right" bgcolor="#dbe5f1"><strong>Registration Number:</strong></td>
<td><input type="text" name="reg_no" id="reg_no" size="35" class="text" placeholder="Registration Number" value="<?php echo $reg_no; ?>" required=""/></td>
</tr>

<tr>
<td align="right" bgcolor="#dbe5f1"><strong>Cost(Tshs):</strong></td>
<td><input type="text" name="cost" id="cost" size="35" class="text" placeholder="Cost" value="<?php echo $cost; ?>" required=""/></td>
</tr>


<tr>
<td colspan="6" align="center" bgcolor="#dbe5f1" ><input type="submit" name="update" class="submit-button" value="SAVE CHANGES"></td>
</tr>

</table>

</form>
</div>


</body>


</html>

最佳答案

从您的 php 代码中删除 while 循环,因为更新是基于 id 的一条记录代码如下:

if(isset($_GET['edit_invoice'])){
$edit_i_id = $_GET['edit_invoice'];
$select_invoice = "select * from invoice where i_id='$edit_i_id'";
$run_query = mysqli_query($con, $select_invoice);
$row_invoice = mysqli_fetch_array($run_query);

$i_id = $row_invoice['i_id'];
$reg_no = $row_invoice['reg_no'];
$cost = $row_invoice['cost'];
}

关于php - 无法从 phpmyadmin 回显数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44905937/

25 4 0