gpt4 book ai didi

PHP - 值未显示在编辑表单中

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:30 26 4
gpt4 key购买 nike

即使我将 php 代码放在表单中以从数据库中检索值,它也没有在下拉列表和文本框中显示该值。该代码工作正常并且可以更新值但是在我刷新页面后它没有显示该值。看起来不错,但似乎找不到我犯的错误。

<?php
require("config.php");
$id = $_GET['id'];

$sql = "SELECT * FROM contracts WHERE id= '$id'";
$result = $con->query($sql);


while ($row = $result->fetch_assoc())
{
$client_type = $row['client_type'];

?>

<html>
<head>
<title> Submit a Contract </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>
<form method="post" action="" enctype="multipart/form-data">

ID: <?php echo $id; ?><br>
<input type="hidden" name="id" value="<?php echo $id; ?>" />

Division:
<select name="client_details" />
<option value="Choose" <?php $row['client_details'] == 'Choose' ? print "selected" : ""; ?> />Choose Division...</option>
<option value="Distribution" <?php $row['client_details'] == 'Distribution' ? print "selected" : ""; ?> />Distribution</option>
<option value="Transmission" <?php $row['client_details'] == 'Transmission' ? print "selected" : ""; ?> />Transmission</option>
<option value="Generation" <?php $row['client_details'] == 'Generation' ? print "selected" : ""; ?> />Generation</option>
<option value="Procument" <?php $row['client_details'] == 'Procument' ? print "selected" : ""; ?> />Procument</option>
<option value="Other" <?php $row['client_details'] == 'Other' ? print "selected" : ""; ?> />Others</option>
</select>
<br><br>
Others:
<input type="text" name="client_details" value="<?php $row['client_details']; ?>">

<input type="submit" name="submit" value="Submit"/>
</form>
</body>

</html>

<?php
}

if(isset($_POST['submit']))
{

$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;

if($client_details == 'Other'){
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
}
$query = "UPDATE contracts set `client_details` = '$client_details' WHERE `id` = '$id'";

if ($con->query($query) === TRUE)
{
echo "<br><br> Updated successfully <br>";

echo $query;


}
else {
echo "Error: " . $query . "<br>" . $con->error;
}

$con->close();
}

?>

最佳答案

<option value="Choose" <?php echo $row['client_details'] == 'Choose' ? print "selected" : ""; ?> />Choose Division...</option>

你的代码很好,只需在工作之前添加 echo

关于PHP - 值未显示在编辑表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com