【问题标题】:What is the proper syntax to save this data to a database?将此数据保存到数据库的正确语法是什么?
【发布时间】:2011-12-08 21:15:35
【问题描述】:

我是 PHP 新手,无法理解数据是如何从表单传递到数据库的。

我的表单:

<select name="parentgallery" id="parentgallery">
<option value="0" ><?php _e('Choose gallery', 'nggallery') ?></option>
<?php
    foreach($this->gallerylist as $gallery) {

        //special case : we check if a user has this cap, then we override the second cap check
        if ( !current_user_can( 'NextGEN Upload in all galleries' ) )
            if ( !nggAdmin::can_manage_this_gallery($gallery->author) )
                continue;

        $name = ( empty($gallery->title) ) ? $gallery->name : $gallery->title;
        echo '<option value="' . $gallery->gid . '" >' . $gallery->gid . ' - ' . $name . '</option>' . "\n";
    }                   ?>
</select>

我制作的这个select 与一个工作的GalleryTitle var 并排在同一页面上传递给这个函数。所以我猜这是将数据传递到数据库的好地方:

if ($_POST['addgallery']){
    check_admin_referer('ngg_addgallery');

    if ( !nggGallery::current_user_can( 'NextGEN Add new gallery' ))
        wp_die(__('Cheatin&#8217; uh?'));

    $newgallery = esc_attr( $_POST['galleryname']);
    if ( !empty($newgallery) )
        nggAdmin::create_gallery($newgallery, $defaultpath);
}

PHP 的问题(与我习惯使用的 Rails 不同)是我看不到这些数据传递到数据库的生命线。我只能猜测传递了什么以及如何接收。

问题:

如何将我的parentgallery 值与galleryname 变量一起发布到数据库?

【问题讨论】:

    标签: php forms wordpress plugins customization


    【解决方案1】:

    如果不了解您尝试修改的任何现有软件的 create_gallery 函数的基本行为,则无法回答此问题。

    通过查看这个,我能告诉您的最好的信息是您在表单上选择的 parentgallery 的值,看起来它应该在接收函数中以 $_POST['parentgallery'] 的形式提供。实现的其余部分过于依赖现有应用程序的细节。

    【讨论】:

      最近更新 更多