【问题标题】:Update using php and mysql使用 php 和 mysql 更新
【发布时间】:2017-04-15 17:07:47
【问题描述】:

我已经按照在线教程使用 CRUD。然而,我来到了更新部分,我在 GET 函数和 fetch_row 方面遇到了一些问题。

未定义变量:第 69 行 C:\xampp\htdocs\Website\editsuppliers.php 中的 fetched_row 是一条错误消息,下一条是未定义索引:editsuppliers

这是我目前所拥有的。

<?php 
include_once 'connect.php' ;
if(isset($_GET['editsuppliers']))
{
 $sql_query="SELECT * FROM suppliers WHERE SuppliersID=".$_GET['editsuppliers'];
 $result_set=mysql_query($sql_query);
 $fetched_row=mysql_fetch_array($result_set);
}
if(isset($_POST['btn-update']))
{
 // variables for input data
$SupplierID = $_POST['SupplierID'];
 $SupplierName = $_POST['SupplierName'];
 $Address = $_POST['Address'];
 $EmailAddress = $_POST['EmailAddress'];
 $PhoneNumber = $_POST['PhoneNumber'];
  // variables for input data

 // sql query for update data into database
 $sql_query = "UPDATE suppliers SET SupplierID='$SupplierID',SupplierNamee='$SupplierName',Address='$Address',EmailAddress='$EmailAddress',PhoneNumber'$PhoneNumber' WHERE SupplierID=".$_GET['editsuppliers'];
 // sql query for update data into database

 // sql query execution function
 if(mysql_query($sql_query))
 {
  ?>
  <script type="text/javascript">
  alert('Data Updated Successfully');
  window.location.href='suppliers.php';
  </script>
  <?php
 }
 else
 {
  ?>
  <script type="text/javascript">
  alert('error occured while updating data');
  </script>
  <?php
 }
 // sql query execution function
}
if(isset($_POST['btn-cancel']))
{
 header("Location: suppliers.php");
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Suppliers</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>

<div id="header">
 <div id="content">
    <label</label>
    </div>
</div>

<div id="body">
 <div id="content">
    <form method="post">
    <table align="center">
    <tr>
    <td><input type="text" name="SupplierID" placeholder="Supplier ID" value="<?php echo $fetched_row['SupplierID']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="SupplierName" placeholder="Supplier Name" value="<?php echo $fetched_row['SupplierName']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="Address" placeholder="Address" value="<?php echo $fetched_row['Address']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="EmailAddress" placeholder="Email Address" value="<?php echo $fetched_row['EmailAddress']; ?>" required /></td>
    </tr>
    <tr>
    <td><input type="text" name="PhoneNumber" placeholder="Phone Number" value="<?php echo $fetched_row['PhoneNumber']; ?>" required /></td>
    </tr>
    <tr>
    <td>
    <button type="submit" name="btn-update"><strong>UPDATE</strong></button>
    <button type="submit" name="btn-cancel"><strong>Cancel</strong></button>
    </td>
    </tr>
    </table>
    </form>
    </div>
</div>

</center>
</body>
</html>

【问题讨论】:

标签: php sql crud


【解决方案1】:

根据您的声明,确保您在 url 中传递 editsuppliers

请详细解释错误。

【讨论】:

  • 我该怎么做?每个文本框中出现有关 fetched_row 的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2013-09-30
  • 2016-08-07
  • 1970-01-01
  • 2015-04-01
  • 2013-06-17
相关资源
最近更新 更多