[英]Can't echo data from phpmyadmin
我已經創建了這樣的表格並且可以正常工作,但是在最后兩個表格上都無法正常工作時,它顯示警告未定義的變量: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>
如果isset($_GET['edit_invoice'])
為false,則$reg_no
在以后的腳本中不存在(您要在其中回顯它)。
將$ reg_no放在您的isset($ _ GET ...)檢查上方,並將其設置為null或空字符串。
$reg_no = null;
if (isset($_GET['edit_invoice'])) {
// your code...
}
編輯:對$cost
和$i_id
做同樣的$i_id
;)
請考慮Tom Uddings對SQL注入的評論!
由於更新是基於id的一條記錄,因此從您的php代碼中刪除while循環。代碼將如下所示:
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'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.