我正在尝试在表格中更新我的供应商信息
这是我的editsupplier表单代码
<?php
$SupplierID = $_GET['SupplierID'] = $row['SupplierID'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
//Run query
$result1 = mysql_query("SELECT * FROM suppliers WHERE SupplierID=$SupplierID");
while($row = mysql_fetch_array($result1)){
$SupplierID = $_GET['SupplierID'] = $row['SupplierID'];
$SupplierName = $row['SupplierName'];
$Currency = $row['Currency'];
$Location = $row['Location'];
$ContactNumber = $row['ContactNumber'];
$Email = $row['Email'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Harrison Spinks</title>
</head>
<body>
<div id="wrapper">
<?php include('includes/header.php'); ?>
<?php include('includes/nav.php'); ?>
<div id="content">
<h3><center>Edit Supplier Information</center></h3>
<p>Please enter all the following details to edit a supplier</p>
</div>
<div>
<br>
</br>
<form action="Edit_Supp.php" method="post">
<br>
</br>
<input type="hidden" name="SupplierID" value="<?php echo $SupplierID;?>"/>
Supplier Name: <input type="text" name="SupplierName" value="<?php echo $SupplierName ;?>" />
<br>
</br>
Currency: <input type="text" name="Currency" value="<?php echo $Currency ;?>" />
<br>
</br>
Location: <input type="text" name="Location" value="<?php echo $Location ;?>" />
<br>
</br>
Contact Number:<input type="text" name="ContactNumber" value="<?php echo $ContactNumber ;?>" />
<br>
</br>
Email:<input type="text" name="Email" value="<?php echo $Email ;?>" />
<br>
</br>
<input type="submit" value= "Edit Supplier Information"/>
</form>
</div>
</body>
</html>
错误是:
Notice: Undefined variable: row in E:\xampp\htdocs\EditSupForm.php on line 2
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\xampp\htdocs\EditSupForm.php on line 8
这是表单背后的代码:
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("supplierdetails");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Run a query
$SupplierID= $_POST['SupplierID'] = $row ["SupplierID"];
$result1 = mysql_query ("SELECT * FROM suppliers WHERE SupplierID= '".$SupplierID."'") or die(mysql_error());
$row = mysql_fetch_array($result1);
$SupplierID = $_POST['SupplierID'] = $row ["SupplierID"];
$SupplierName = $_POST['SupplierName'];
$Currency = $_POST['Currency'];
$Location = $_POST['Location'];
$ContactNumber = $_POST['ContactNumber'];
$Email = $_POST['Email'];
$SupplierID = $row['SupplierID'];
$query = "UPDATE suppliers SET SupplierID = '".$SupplierID."', SupplierName= '".$SupplierName."', Currency = '".$Currency."', Location = '".$Location."', ContactNumber = '".$ContactNumber."', Email = '".$Email."' WHERE SupplierID = '".$id."'";
$result1 = mysql_query($query);
//Check whether the query was successful or not
if($result1)
{
echo "Supplier Updated";
header ("Location: Supplier.php");
}
else
{
die ("Query failed");
}
?>