繁体   English   中英

将数据保存到数据库的正确语法是什么?

[英]What is the proper syntax to save this data to a database?

我是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此函数的工作GalleryTitle变量一起。 所以我想这是将数据传递到数据库的好地方:

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相对)是,我看不到此数据的生命线传递到数据库。 我只能猜测正在通过什么以及如何被接受。

问题:

如何将我的parentgallerygalleryname var一起发布到数据库?

这太具体了,无法知道您要修改的任何现有软件的create_gallery函数的基本行为。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM