php - 将信息更新到数据库中会在更新时删除一些

标签 php mysql

我有一个用于更新用户配置文件的表单,并使用了一些 PHP 代码来检查字段是否为空,如果不是,则该字段不会显示,但它会清除数据库中该字段中的信息。我该如何阻止这种情况发生?

这是我的代码:

<?php 
                if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
                echo 'Your details have been updated!';
                } else {
                if (empty($_POST) === false && empty($errors) === true) {

                    $update_data = array(
                        'aboutme'       => $_POST['aboutme'],
                        'facebook'      => $_POST['facebook'],
                        'twitter'       => $_POST['twitter'],
                        'google'        => $_POST['google'],
                        'linked'        => $_POST['linked'],
                        'pokerstars'    => $_POST['pokerstars'],
                        'pokerstarsfr'  => $_POST['pokerstarsfr'],
                        '888poker'      => $_POST['888poker'],
                        'fullflush'     => $_POST['fullflush'],
                        'partypoker'    => $_POST['partypoker'],
                    );

                update_user($session_user_id, $update_data);
                header('Location: settings.php?success');
                exit();

                } else if (empty($errors) === false) {
                    echo output_errors($errors);
                }
            }
            ?>

这是表单代码:

<form class="margin-bottom-40" role="form" method="post" action="">
                        <div class="form-group">
                            <label>About Me</label><br>
                            <textarea class="form-control" rows="15" name="aboutme"><?php echo $user_data['aboutme']; ?></textarea>
                        </div>
                        <div class="form-group">
                            <label>Facebook</label>
                            <input type="text" class="form-control" name="facebook" placeholder="Please start with www." value="<?php echo $user_data['facebook']; ?>">
                        </div>
                        <div class="form-group">
                            <label>Twitter</label>
                            <input type="text" class="form-control" name="twitter" placeholder="Please start with www." value="<?php echo $user_data['twitter']; ?>">
                        </div>
                        <div class="form-group">
                            <label>Google+</label>
                            <input type="text" class="form-control" name="google" placeholder="Please start with www." value="<?php echo $user_data['google']; ?>">
                        </div>
                        <div class="form-group">
                            <label>LinkedIn</label>
                            <input type="text" class="form-control" name="linked" placeholder="Please start with www." value="<?php echo $user_data['linked']; ?>">
                        </div>
                        <input type="hidden" value="<?php echo $user_data['email']; ?>" name="email">

                        <h3>Poker ID's</h3>
                        Please note: You can only enter your poker ID once, after this it can NOT be changed.<br><br>
                        <div class="form-group">
                        <label>PokerStars ID</label> 
                        <input type="text"  class="form-control" value="<?php echo $user_data['pokerstars']; ?>" name="pokerstars" <?php if(!empty($user_data['pokerstars'])) { echo 'disabled'; } ?> >
                        </div>
                        <div class="form-group">
                        <label>PartyPoker ID</label> 
                        <input type="text"  class="form-control" value="<?php echo $user_data['partypoker']; ?>" name="partypoker" <?php if(!empty($user_data['partypoker'])) { echo 'disabled'; } ?> >
                        </div>
                        <div class="form-group">
                        <label>Full Flush Poker ID</label> 
                        <input type="text"  class="form-control" value="<?php echo $user_data['fullflush']; ?>" name="fullflush" <?php if(!empty($user_data['fullflush'])) { echo 'disabled'; } ?> >
                        </div>
                        <?php if (empty($user_data['888poker'])): ?>
                            <div class="form-group">
                            <label>888 Poker ID</label>
                            <input type="text" name="888poker" class="form-control" value="<?php echo $user_data['888poker']; ?>">
                            </div>
                        <?php endif; ?>
                        <?php if (empty($user_data['pokerstarsfr'])): ?>
                            <div class="form-group">
                            <label>PokerStars.fr ID</label>
                            <input type="text" name="pokerstarsfr" class="form-control">
                            </div>
                        <?php endif; ?>

                        <br><br>
                        <button type="submit" class="btn-u">Update!</button>
                    </form>

我已经尝试了几种方法,您可以从表单中的不同类型的 php 代码中看到,但还没有成功。

最佳答案

当您将表单域设置为禁用时,它甚至不会被发送到服务器。如果您只想防止用户编辑该字段,则应改用readonly

编辑:

此外,如果您不希望用户更改该值,则必须确保该值未在服务器端更改。从字段中删除 readonly 属性真的很容易。

关于php - 将信息更新到数据库中会在更新时删除一些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24149792/

相关文章:

php - 随机(有权重偏差)从数据库中选择行?

php - Joomla TPlancer 组件添加新字段并显示

php - mysql自身与2个字段的关系

php - 使用php以html形式更新mysql

php - 如何将 Wordpress 注销重定向到自定义 URL

php - 如何在 Symfony2 中测试响应头?

php - 使用 proc_open 时从 STDIN 管道读取

mysql - 您可以手动管理事务提交/回滚吗?

php - 多个 MySQL 查询在本地计算机上运行,​​但在远程计算机上运行不正常

php - 使用ini_set