我有一张桌子:
CREATE TABLE siteConfig (
settingName VARCHAR(64) NOT NULL,
value VARCHAR(255),
PRIMARY KEY (settingName)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
显示这些设置。设置显示.php
$setting = siteConfig::find_all();
$this_page = array(
'recaptcha_public_key','recaptcha_private_key','spam_register','spam_login',
'spam_register_emp','spam_login_emp','spam_apply','spam_contact','spam_share',
'spam_feedback','spam_forgot','spam_rsc'
);
foreach ( $setting as $s )
{
if( in_array($s->settingName, $this_page) )
{
$_SESSION['set_ses'][ $s->settingName ] = isset($_SESSION['set_ses'][ $s->settingName ]) ? $_SESSION['set_ses'][ $s->settingName ] : $s->value;
}
}
显示这些设置的 html 的一部分。
<tr>
<td> </td>
<td>{lang mkey='label' skey='spam_register'}</td>
<td><input type="checkbox" name="txt_setting[spam_register]" id="spam_register" class="checkboxField" {if $smarty.session.set_ses.spam_register == 1 } checked="checked"{/if} /></td>
</tr>
一旦所有信息都更改,则此页面将其保存到数据库。更新.php
foreach( $_POST['txt_setting'] as $k => $v )
{
$setting->settingName = $k;
$setting->value = $v;
if( $setting->updateSiteConfig() )
$k = true;
}
当我选中该框时,我的 update.php 什么也看不到。
我不知道如何从这些复选框中获取 1 或 0 值。
固定的.................
$yes_or_no_key=array(list of my keys);
if( in_array($k, $yes_or_no_key) )
{
$setting->value = $_POST['txt_setting'][$k] == 'on' ? 1 : 0;
}
这解决了我的问题。感谢您的快速回复。