再次编辑这个问题。
这是我现在的进展,我将代码转移到另一张表并使其更清晰,没有错误,但仍然没有更新我的表。对于那些在我之前的问题上回答的人,谢谢你的善意。
编辑代码。
"<a href=\"edit.php?id=". $row['ID'] ."\">Edit</a>". "</td>";
这是我的新编辑.php
<!DOCTYPE html>
<body>
<form method="post" action="edit1.php">
Components: <input type="text" name="Components"> <br /><br />
Manufacturer: <input type="text" name="Manufacturer"> <br /><br />
ManufacturerPN: <input type="text" name="ManufacturerPN"> <br /><br />
Description: <input type="text" name="Description"> <br /><br />
Quantity: <input type="number" name="Quantity"> <br /><br />
<br />
<input type="submit" name="submit"> <br /><br />
</form>
</body>
</html>
这是edit1.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$link = mysql_connect($dbhost, $dbuser, $dbpass);
if (isset($_POST['submit'])) {
$Components = $_POST['Components'];
$Manufacturer = $_POST['Manufacturer'];
$ManufacturerPN = $_POST['ManufacturerPN'];
$Description = $_POST['Description'] ;
$Quantity = $_POST['Quantity'];
$id = $_GET['ID'];
$sql= "UPDATE form SET Components='$Components' , Manufacturer='$Manufacturer' , ManufacturerPN='ManufacturerPN' , Description='$Description' , Quantity='Quantity' WHERE ID = '$id'";
mysql_select_db('practice1');
$result = mysql_query($sql, $link);
if(!$result){
die ('Could not enter data:' . mysql_error());
}else if ($result){
header("location:Inventory.php");
}
}
?>
我是否在正确的道路上?
答案 0 :(得分:0)
请试试这个。括号似乎存在问题。
<!DOCTYPE html>
<body>
<?PHP
$link = mysql_connect("localhost","root","");
mysql_select_db("practice1", $link);
if(isset($_GET['ID']))
{
$id = $_GET['ID'];
if(isset($_POST['submit'])) {
$Components = $_POST['Components'];
$Manufacturer = $_POST['Manufacturer'];
$ManufacturerPN = $_POST['ManufacturerPN'];
$Description = $_POST['Description'];
$Quantity = $_POST['Quantity'];
$query3 = mysql_query("UPDATE form set Components='$Components', Manufacturer='$Manufacturer' , ManufacturerPN='$ManufacturerPN' , Description='$Description' , Quantity='$Quantity' where ID=$id");
if($query3){
header("location:Inventory.php");
}
}
}
$query=mysql_query("SELECT * FROM form where ID='$id'");
$row=mysql_fetch_array($query);
?>
<form method="post" action="">
Components: <input type="text" name="Components" value="<?php echo $row["Components"]?>"> <br /><br />
Manufacturer: <input type="text" name="Components" value="<?php echo $row["Manufacturer"]?>"> <br /><br />
ManufacturerPN: <input type="text" name="Components" value="<?php echo $row["manufacturerPN"]?>"> <br /><br />
Description: <input type="text" name="Components" value="<?php echo $row["Description"]?>"> <br /><br />
Quantity: <input type="number" name="Components" value="<?php echo $row["Quantity"]?>"> <br /><br />
<br />
<input type="submit" name="submit"> <br /><br />
</form>
</body>
</html>
答案 1 :(得分:0)
试试这个:
$link = mysql_connect("localhost","root","", "dbName");
$result=mysqli_query($link,$sql); // $sql = YOUR QUERY
// Numeric array
$row=mysqli_fetch_array($result,MYSQLI_NUM);
答案 2 :(得分:0)
<强> 1)强>
每个<input>
具有相同的名称。所以,
更改
<form method="post" action="<?php $_PHP_SELF ?>">
Components: <input type="text" name="Components"> <br /><br />
Manufacturer: <input type="text" name="Components"> <br /><br />
ManufacturerPN: <input type="text" name="Components"> <br /><br />
Description: <input type="text" name="Components"> <br /><br />
Quantity: <input type="number" name="Components"> <br /><br />
<br />
<input type="submit" name="submit"> <br /><br />
</form>
要
<form method="post" action="<?php $_PHP_SELF ?>">
Components: <input type="text" name="Components"> <br /><br />
Manufacturer: <input type="text" name="Manufacturer"> <br /><br />
ManufacturerPN: <input type="text" name="ManufacturerPN"> <br /><br />
Description: <input type="text" name="Description"> <br /><br />
Quantity: <input type="number" name="Quantity"> <br /><br />
<br />
<input type="submit" name="submit"> <br /><br />
</form>
2)更改
$sql = "UPDATE form SET Components=$Components, Manufacturer=$Manufacturer , ManufacturerPN=$ManufacturerPN , Description=$Description , Quantity=$Quantity where ID=$id";
要
$sql = "UPDATE form SET Components='$Components', Manufacturer='$Manufacturer' , ManufacturerPN='$ManufacturerPN' , Description='$Description' , Quantity='$Quantity' WHERE ID=$id";
3)将mysql_select_db('practice1');
更改为mysql_select_db('practice1', $link);
4)更改
$Components = isset($_POST['Components']);
$Manufacturer = isset($_POST['Manufacturer']);
$ManufacturerPN = isset($_POST['ManufacturerPN']);
$Description = isset($_POST['Description']);
$Quantity = isset($_POST['Quantity']);
$id = isset($_GET['ID']);
要
$Components = $_POST['Components'];
$Manufacturer = $_POST['Manufacturer'];
$ManufacturerPN = $_POST['ManufacturerPN'];
$Description = $_POST['Description'];
$Quantity = $_POST['Quantity'];
$id = $_GET['ID'];
更新代码:
<?php
if(isset($_POST['submit'])) {
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$link = mysql_connect($dbhost, $dbuser, $dbpass);
$db = mysql_select_db('practice1', $link);
if (!$link){
die('Could not connect: ' . mysql_error());
}
$Components = $_POST['Components'];
$Manufacturer = $_POST['Manufacturer'];
$ManufacturerPN = $_POST['ManufacturerPN'];
$Description = $_POST['Description'];
$Quantity = $_POST['Quantity'];
$id = $_GET['ID'];
$sql = "UPDATE form SET Components='$Components', Manufacturer='$Manufacturer' , ManufacturerPN='$ManufacturerPN' , Description='$Description' , Quantity='$Quantity' WHERE ID=$id";
$retval = mysql_query($sql, $link);
if(!$retval){
die ('Could not enter data:' . mysql_error());
}
header("location:Inventory.php");
mysql_close($link);
} else {?>
<form method="post" action="<?php $_PHP_SELF ?>">
Components: <input type="text" name="Components"> <br /><br />
Manufacturer: <input type="text" name="Manufacturer"> <br /><br />
ManufacturerPN: <input type="text" name="ManufacturerPN"> <br /><br />
Description: <input type="text" name="Description"> <br /><br />
Quantity: <input type="number" name="Quantity"> <br /><br />
<br />
<input type="submit" name="submit"> <br /><br />
</form>
<?PHP }?>
</body>
</html>