【问题标题】:php form with checkbox带有复选框的php表单
【发布时间】:2013-04-13 15:13:22
【问题描述】:

我有以下 php 代码。如何修改复选框以在我的数据库中保留作为“勾号”的选定值,然后再次打印回来?

<?php


if ( isset($_GET['success']) === true && empty($_GET['success'])===true ){
echo'Updated Sucessfuly!';?>

<?php 
    }else{

    if( empty($_POST) === false  &&  empty($errors) === true ){

    $update_data_profile_career = array(
                'Consulting' => $_POST['Consulting'],
                'user_id' => $session_user_id,
                      );
                update_user_profile_career($session_user_id, $update_data_profile_career);

                header('Location: profile_update_career_goal.php?success');                             
                exit();


    }else if ( empty($errors) === false ){
                        echo output_errors($errors);
                        echo'</br></br>';
    }


?>

<input type="checkbox" name="Consulting[]" value="<?php echo $user_data_profile_career['Consulting'];     ?>" />Consulting

【问题讨论】:

  • 您要根据数据库返回值选择checkbox
  • 我想在表单中选中它,然后下次我再次打开表单时看到它被选中
  • 你为什么使用输入数组?您是否有超过 1 个咨询复选框?

标签: php forms checkbox


【解决方案1】:
<?php echo $user_data_profile_career['Consulting']?' checked':''; ?>

【讨论】:

    【解决方案2】:

    您必须检查 db 中的值并使用 checked='checked' 来检查复选框

    <input type="checkbox" name="Consulting[]" value="<?php echo $user_data_profile_career['Consulting'];     ?>" 
    <?php isset($user_data_profile_career['Consulting']) ? "checked='checked'":'' ?> />Consulting
    

    【讨论】:

    • 我的表将值存储在名为“Consulting”的字段中,它是 varchar 32。我需要对我的表进行任何更改吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    相关资源
    最近更新 更多