[英]What is the proper syntax to save this data to a database?
I'm new to PHP, and I'm having trouble understanding how data is passed from forms to the database. 我是PHP的新手,我无法理解如何将数据从表单传递到数据库。
My Form: 我的表格:
<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>
This select
I made is alongside a working GalleryTitle
var that is passed to this function on the same page. 我所做的select
与在同一页面GalleryTitle
此函数的工作GalleryTitle
变量一起。 So I'm guessing this is a good place to pass the data to the database : 所以我想这是将数据传递到数据库的好地方:
if ($_POST['addgallery']){
check_admin_referer('ngg_addgallery');
if ( !nggGallery::current_user_can( 'NextGEN Add new gallery' ))
wp_die(__('Cheatin’ uh?'));
$newgallery = esc_attr( $_POST['galleryname']);
if ( !empty($newgallery) )
nggAdmin::create_gallery($newgallery, $defaultpath);
}
The trouble with PHP ( as opposed to Rails which I'm used to ), is I can't see the lifeline of this data getting passed to the database. PHP的麻烦(与我以前习惯的Rails相对)是,我看不到此数据的生命线传递到数据库。 I can only guess what is getting passed and how it's being received. 我只能猜测正在通过什么以及如何被接受。
The Question: 问题:
How can I post to the database my parentgallery
value alongside the galleryname
var? 如何将我的parentgallery
值galleryname
var一起发布到数据库?
This is too specific to answer without knowing the underlying behavior of the create_gallery function of whatever existing software you're trying to modify. 这太具体了,无法知道您要修改的任何现有软件的create_gallery函数的基本行为。
The best I can tell you by looking at this, is the value of your parentgallery select on the form, looks like it should be available as $_POST['parentgallery'] in the receiving function. 通过查看,我能告诉您的最好的情况是,您在表单上选择的parentgallery的值,看起来应该在接收函数中以$ _POST ['parentgallery']的形式提供。 The rest of the implementation, is too dependent on the specifics of that existing application. 其余的实现太依赖于现有应用程序的细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.