php - 根据从数据库检索的值检查单选按钮

标签 php

我有单选按钮想要检查从数据库检索的值是否为"is"。 在同一个论坛上也有同样的问题,但尝试后仍然没有成功。我也无法对我的问题发表任何评论,因为我没有足够的声誉。 与我的问题相同的链接是: How to set the value for Radio Buttons When edit?

下面是显示获取的数据的表单代码:

<?php
error_reporting(0);
$server="localhost";
$user="root";
$password="";
$database="camouflage_studio";

$con = mysqli_connect($server,$user,$password,$database);
if (mysqli_connect_errno())
  {
  echo "Connection Error: " . mysqli_connect_error();
  }
//receiving CINC from search form and getting record on it's basis
$cnic = $_POST['search'];
$data = "SELECT * FROM personal_detail WHERE CNIC='$cnic'";
if($query = mysqli_query($con, $data)){
      $data2 = mysqli_fetch_array($query);  //i think it's used for to know the total number of rows fetched/retrieved 
}else{ echo "Query Not Executed!";}
?>
<!DOCTYPE html>
<html>
<head>
<title>Camouflage Studio - Welcome</title>
<!-- My CSS coding starts here -->
</head>
<body>
<!-- form to display Retrieved/Fetched data-->
<center>
<form action="update.php" method="post">
<fieldset style="width:50%"><legend>Please do the required changes</legend><br>
<label for="Name">Name :<br></label><input name="name" type="text" size="20" maxlength="40" value="<?php echo $data2[Name]?>"><br>
<label for="CNIC">CNIC :<br></label><input name="cnic" type="text" size="20" maxlength="15" value="<?php echo $data2[CNIC]?>"><br>
<label for="Date">Booking Date :<br></label><input name="booking-date" type="date" size="20" value="<?php echo $data2[Date]?>"><br>

<!-- <label for="Ocassion">Ocassion :<br></label> -->
<label for="Ocassion">Ocassion :<br></label><input name="ocassion" type="text" size="20" maxlength="15" value="<?php echo $data2[Ocassion]?>"><br>

<label for="Address">Address :<br></label><input name="address" type="text" size="20" maxlength="11" value="<?php echo $data2[Address]?>"><br>

<label for="Phone Number">Phone Number :<br></label><input name="phone-no" type="text" size="20" maxlength="11" value="<?php echo $data2[Phone_No]?>"><br>
<label for="Bride Mobile">Bride Mobile :<br></label><input name="bride-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Bride_Mobile]?>"><br>
<label for="Groom Mobile">Groom Mobile :<br></label><input name="groom-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Groom_Mobile]?>"><br>
<label for="Family Mobile">Family Mobile :<br></label><input name="family-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Family_Mobile]?>"><br>
<label for="Email">Email :<br></label><input name="email" type="text" size="20" maxlength="30" value="<?php echo $data2[EMail]?>"><br>
<label for="Who may I Thank for Refering You?">Who may I Thank for Refering You? :<br></label><input name="refering" type="text" size="20" maxlength="40" value="<?php echo $data2[Referring]?>"><br>
<label for="Do you provide consent to share images on our official web page">Do you provide consent to share images on our official web page? :<br><br></label><input type="radio" name="share" <?php echo ($data2[Share]=='Yes')?'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="share" <?php echo ($data2[Share]=='Yes')?'checked':'' ?> value="No">No<br><br>
<label for="If yes, with Identity">If yes, with Identity? :<br><br></label><input type="radio" name="permission" <?php echo ($data2[Permission]=='Yes')?'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="permission" <?php echo ($data2[Permission]=='Yes')?'checked':'' ?> value="No">No<br><br>
<!-- To center the button i'm embedding the buttons in a paragraph with an id as well. the id is used for CSS in head -->
<p id="btn">
<input type="submit" value="Update Record" name="submit_display_data_form" style="font-size:16px"></p>
</fieldset>
</form>
</center>
</body>
</html>

最佳答案

$Share = 'Yes';
$Permission = 'Yes';
    <label for="Do you provide consent to share images on our official web page">
        Do you provide consent to share images on our official web page? :
    </label>
    <input type="radio" name="share" <?php echo ($Share =='Yes')? 'checked':'' ?> value="Yes">Yes<br>
    <input type="radio" name="share" <?php echo ($Share =='No')? 'checked':'' ?> value="No">No<br><br>

    <label for="If yes, with Identity">If yes, with Identity? :<br><br></label>
    <input type="radio" name="permission" <?php echo ($Permission=='Yes')?'checked':'' ?> value="Yes">Yes<br>
    <input type="radio" name="permission" <?php echo ($Permission=='No')?'checked':'' ?> value="No">No<br><br>

关于php - 根据从数据库检索的值检查单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45239562/

相关文章:

javascript - 聊天框滚动到底部?

php - for 在不同表中查找 id 的过程,如果没有该 id 的条目则将其插入

php - 使用 Zend_Mail + Zend_Mime 在 Zend Framework 2 中创建 HTML 电子邮件

php - 如何使用 dompdf 创建多个页面

php - 按时间戳对组内的行进行排序

php - 使用 Zend Framework 保存密码

php - 使用 Intent 的 EXTRA_TEXT 中没有数据

javascript - AJAX 请求填充弹出窗口,仅对 php 文件运行一次

php - 如何使用 php 获取服务器 CPU 使用率和 RAM 使用率?

php - PHP 超时会阻止同一网络上的人们加载页面吗?