dongyan8896 2013-03-25 09:07
浏览 28
已采纳

PHP和SQL CheckBox

I have written a form that allows for checkbox inputs in my SQL tables I have made the checkboxes as Variables.

What i want is when i display the forms that it should show the checkbox with the value as inputted by the initial input yes or no again.

<input type="checkbox" name="basic_inter" id="basic_inter" value="<? echo   
$rows['basic_inter']; ?>">

If I use it this way it doesn't show the value of the checkbox. What is best way to display the checkbox is it due to the tables being Var or is it the method I echo it back to the screen?

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE company_name='$query'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
  <form name="form" method="post" action="control_adminupdateresellered.php">
  <input type="hidden" name="company_name" value="<?=$query?>" />

Then this is some of the echo code I use others not fully included as they just are text

<input type="checkbox" name="basic_inter" id="basic_inter" value="<? echo 
$rows['basic_inter']; ?>">
          </strong></div>              </td>
        <td width="81"><div align="right"><strong>LBS Add-on:<br>
          R500-00 P/M
        </strong></div></td>
        <td width="66"><div align="left"><strong>
          <input type="checkbox" name="lbs_inter" id="lbs_inter" value="<? echo  
$rows['lbs_inter']; ?>">
  • 写回答

3条回答 默认 最新

  • duanjiuhong5843 2013-03-25 09:24
    关注

    Please try this

       <input type="checkbox" name="lbs_inter" id="lbs_inter" value="<? echo  
    $rows['lbs_inter']; ?>" <?php if($rows['lbs_inter']=='yes'){ echo "checked";}?>>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word