编辑时如何回显单选按钮的值[关闭]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编辑时如何回显单选按钮的值[关闭]相关的知识,希望对你有一定的参考价值。

我以前曾经问过这个问题。但我尝试了所有解决方案仍然无法获得输出。这就是我做的: - (实际上我的更新页面中的问题)和问题只是单选按钮,我只是想要单选按钮来携带值并使用数据库中的值检查它

update_page.php

<?php
include("config.php");
$item_code= $_GET['item_code'];
$sel = mysql_query("select * from `table 14` where Item_Code='$item_code'");
$get_sel = mysql_fetch_array($sel); ?>
<script type="text/javascript" LANGUAGE="JavaScript">
function getting()
{
var agree=confirm("Confirm Update?");
if (agree)
document.myform2.submit2();

else
return false;
}
</script>
<center>
<h2 class="back" width='1400px'>Update Item Info</h2>

<div class="content">
<p style="margin-top:20px; font-size:20px;"><b><?php echo 
$get_sel['Item_Code']; ?></b></p>
<br />

<div id="main">

<form name="myform2" action="admin_update_process.php?item_code=<?php echo 
$get_sel['Item_Code'];?>" method="POST" >
<table>

<tr>
    <th>Vendor</th>     
    <th>Vendor Desc</th>
    <th>Item Code</th>
    <th>Item Decs</th>
</tr>

<tr>
<td><input autofocus type="text" required name="vendor" 
class="input_teks_upd" size="30px" value='<?php echo $get_sel['Vendor']; ?>' 
/></td>
<td><input autofocus type="text" required name="vendor_desc" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Vendor_Desc']; ?>' /></td>
<td><input autofocus type="text" required name="item_code" 
class="input_teks_upd" size="30px" value='<?php echo $get_sel['Item_Code']; 
?
>' /></td>
<td><input autofocus type="text" required name="item_desc" 
class="input_teks_upd" size="30px" value='<?php echo $get_sel['Item_Desc']; 
?
 >' /></td>
<tr>
    <th>CUR</th>
    <th>Price</th>
    <th>COO</th>
    <th>COO Material</th>
</tr>
<tr>
<td><input autofocus type="text" required name="cur" class="input_teks_upd" 
size="30px" value='<?php echo $get_sel['Cur']; ?>' /></td>
<td><input autofocus type="text" required name="price" 
class="input_teks_upd" size="30px" value='<?php echo $get_sel['Price']; ?>' 
/></td>
<td><input autofocus type="text" required name="coo" class="input_teks_upd" 
size="30px" value='<?php echo $get_sel['Coo']; ?>' /></td>
<td><input autofocus type="text" required name="coo_material" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Coo_Material']; ?>' /></td>
</tr>
<tr>
    <th>PROD L/Time</th>
    <th>MOQ</th>
    <th>Part name/Material</th>
    <th>Normal Shipping Mode</th>
</tr>
<tr>
<td><input autofocus type="text" required name="prod_l_time" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Prod_L_Time']; ?>' /></td>
<td><input autofocus type="text" required name="moq" class="input_teks_upd" 
size="30px" value='<?php echo $get_sel['Moq']; ?>' /></td>
<td><input autofocus type="text" required name="part_name" 
class="input_teks_upd" size="30px" value='<?php echo $get_sel['Part_Name']; 
?
>' /></td>
<td><input autofocus type="text" required name="normal_shipping" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Normal_Shipping']; ?>' /></td>
<tr>
    <th>Shipping Lead Time</th>
    <th>Common/Customize for Onkyo</th>
    <th>Marker Part No</th>
    <th>Aprroval Spec (YES/NO)</th>
</tr>

<tr>
<td><input autofocus type="text" required name="ship_lead" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Shipping_Lead']; ?>' /></td>
<td><input autofocus type="text" required name="common" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Common_Customize']; ?>' /></td>
<td><input autofocus type="text" required name="maker_part" 
class="input_teks_upd" size="30px" value='<?php echo 
$get_sel['Maker_Part_No']; ?>' /></td>
<td><input autofocus type="radio" name="approval" value="YES" 
    <?php echo ($approval=='YES') ? " checked " : "";?>> YES
    <input autofocus type="radio" name="Green_Document" value="NO"
    <?php echo($approval=='NO') ? " checked " : "";?>>NO <br/>
</td>
    <th>Green Document (YES/NO)</th>
    <th>Upload Approval Spec</th>
    <th>Upload Green Document</th>
</tr>
<tr>
 <td><input autofocus type="radio" name="Green_Document" value="YES" 
    <?php echo ($Green_Document=='YES') ? " checked " : "";?>> YES
    <input autofocus type="radio" name="Green_Document" value="NO"
    <?php echo($Green_Document=='NO') ? " checked " : "";?>>NO <br/>
</td>
<td><input  type="file" name="file_approval"/></td>
<td><input  type="file" name="file_green"/></td>
</tr>
</table>
<br>
<input type="submit" name="submit2" value="Confirm Update Data" 
class="admin_button" onClick="return getting();" />

</form>


</div>
</div>  

</center>

update_query.php

<?php
include("config.php");

if (isset($_POST['submit2']))
{
extract($_POST);

$item_code=$_GET['item_code'];

if($item_code==''){

echo "<script type='text/javascript'>";
echo "alert('No details entered. Update Fail.')";
echo "</script>";
echo "<meta http-equiv='refresh' content='0; 
url=".$_SERVER['HTTP_REFERER']."'>";

}
else{
$pro1 = mysql_query("update `table 14` set Vendor='$vendor',Vendor_Desc='$vendor_desc',Item_Code='$item_code',Item_Desc='$item_desc', Cur='$cur', Price='$price', Coo='$coo', Coo_Material='$coo_material', Prod_L_Time ='$prod_l_time', 
Moq='$moq', Part_Name='$part_name', Normal_Shipping='$normal_shipping', Shipping_Lead='$ship_lead', Common_Customize='$common',
Maker_Part_No='$maker_part', Approval_Spec='$approval', Green_Document='$Green_Document' where Item_Code = '$item_code'"); //this the part I send the green_document

if($pro1)
    {
echo "<script type='text/javascript'>";
echo "alert('Item Info Successfully Updated')";
echo "</script>";
echo "<meta http-equiv='refresh' content='0; url=".$_SERVER['HTTP_REFERER']."'>";
}

else
{

echo "<script type='text/javascript'>";
echo "alert('Failed to update, try again')";
echo "</script>";
echo "<meta http-equiv='refresh' content='0; 
url=".$_SERVER['HTTP_REFERER']."'>";
}
}
}
mysql_close()       
答案

你快到了。看看这个,我只是对你的代码做了一些调整,包括回显checked属性

    <b>Green Document (YES/NO):</b>
    <input type="radio"    name="green_document"  value="YES">Yes
    <input type="radio"    name="green_document"  value="NO">No<br>
    <br />

   <td><input type="radio" name="green_document" value="YES" id="YES" 
        <?php echo($green_document=='YES') ? " checked " : "";?>> YES
        <input type="radio" name="green_document" value="NO" id="NO"
        <?php echo($green_document=='NO') ? " checked " : "";?>>NO <br/>
    </td>

以上是关于编辑时如何回显单选按钮的值[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

如何控制单选按钮?从数据库、PHP、MYSQL 回显的数据

使用 PDO 从数据库回显单行时出错

编辑时如何设置单选按钮的值?

自定义单选按钮jqgrid编辑表单

如何从 PHP 中的单选按钮发送值属性 [关闭]

如何以在 php 中作为字符串回显的形式填充单选按钮?