Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 02-07-2006, 07:56 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need assistance with form creation in the ACP

Hello,

(This is a double post because it classifies as both a mySQL question as well as a modification question. If one forum is better suited for this question over the other, I would appreciate it if a moderator would merge the 2 posts in the appropriate forum.)

I have been racking my brain on this for 3 days now and have tried numerous techniques to get this to work. I AM new to mySQL queries, so I know to you seasoned coders this is going to seem very remedial.

I have a table I created. This is the content and how I installed it:

CREATE TABLE this_data
(
site_name varchar(50),
site_url varchar(50),
admin_email varchar(50),
home_it int
);

I want to make a form in the acp that allows me to enter the values for these columns. If they exist already, they will be dropped and the new value inserted.

The output of these values will not be displayed. Instead, they will be placed in a settings file as variables like this (not sure if this is even correct!):

PHP Code:
<?php
$site_name 
$DB_site->query("SELECT site_name from this_data");
$site_url $DB_site->query("SELECT site_url from this_data");
$admin_email $DB_site->query("SELECT admin_email from aws_data");
$home_it = = $DB_site->query("SELECT home_it from this_data");
?>
I have gone through the adminfunctions.php file and that is just confusing me even more.

I know I want to create something like this:

PHP Code:
// ## Add Settings ##
//this would actually be: settings_admin.php?do=add

if ($_REQUEST['do'] == 'add')
{

    
$vbulletin->input->clean_array_gpc('p', array(
        
'site_name'    => TYPE_STR,
        
'site_url' => TYPE_STR,
        
'admin_email'    => TYPE_STR,
        
'home_it'    => TYPE_INT
    
));
    if (empty(
$vbulletin->GPC['site_name']) or empty($vbulletin->GPC['site_url']) or empty($vbulletin->GPC['admin_email']) or empty($vbulletin->GPC['home_it']))
    {
        
print_stop_message('invalid_settings_specified');
    }

    
/*Start Query*/
    
$db->query_write("
        INSERT INTO " 
TABLE_PREFIX "this_data
            (site_name, site_url, admin_email, home_it)
        VALUES
            ('" 
$db->escape_string($vbulletin->GPC['site_name']) . "', '" $db->escape_string($vbulletin->GPC['site_url']) . "', '" $db->escape_string($vbulletin->GPC['admin_email']) . "', '" $db->escape_string($vbulletin->GPC['home_it']) . "')
    "
);

    
define('CP_REDIRECT''settings_admin.php?do=manage');
    
print_stop_message('saved_settings_successfully'$vbulletin->GPC['settings']);

Now I know I have SOME things correct, or at least I think I do!

I just want to be able to see a form with the fields there to add the values. When "submit" is hit, I want it to save that info in the database. If that info exists, I want the new info to replace it.

I would greatly appreciate some help with this. I am really trying to learn how to do all of this but I don't/can't grasp it and I hope with some guidance I will be better capable.

(Please don't post anything like "check out how other people did it, or read this site, etc.) I have been viewing how others have done it and I have been reading so many tutorials on VB and mySQL in general that my eyeballs want to explode. I am just at a point where i am utterly confused and frustrated.

I am a pupil awaiting a teacher. I am showing some initiative here, so help me! lol
Reply With Quote
  #2  
Old 02-10-2006, 09:00 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

I have learned a lot in the past 3 days. lol I have my forms almost completely worked out now.

I am trying to get this to display the inserted content but also change it if it is changed. This is what I have in my file, but i am missing something or wrote something wrong. It doesn't update the info and I don't know why.

PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
@
set_time_limit(0);
 
// #################### START PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('');
$specialtemplates = array('');
// #################### END PRE-CACHE TEMPLATES AND DATA ######################
 
// ########################## START BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/adminfunctions_template.php');
// ########################## END BACK-END ############################

print_cp_header($vbphrase['a_settings_manager']);
if (empty(
$_REQUEST['do']))
{
    
$_REQUEST['do'] = 'manage';
}

// ########################## FORM ############################ 
{
    
$query_settings $db->query_first("SELECT * FROM " TABLE_PREFIX "this_data");
}
if (
$_REQUEST['do'] == 'manage')
{
        
print_form_header('testform''update'); 
        
print_table_header('Settings Configuration');

    
print_input_row($vbphrase['site_name'], 'sitename'$query_settings['site_name']);
    
print_input_row($vbphrase['site_url'], 'siteurl'$query_settings['site_url']);
    
print_input_row($vbphrase['admin_email'], 'adminemail'$query_settings['admin_email']);

        
print_submit_row("Save Settings");
}
// ########################## END FORM ############################ 

// ########################## FORM UPDATE ############################
if ($_POST['do'] == 'update')
{

    
$vbulletin->input->clean_array_gpc('p', array(
        
'site_name'    => TYPE_STR,
        
'site_url'     => TYPE_STR,
        
'admin_email'  => TYPE_STR
    
));

    if (empty(
$vbulletin->GPC['site_name']) or empty($vbulletin->GPC['site_url']) or empty($vbulletin->GPC['admin_email']))
    {
        
print_stop_message('invalid_settings_specified');
    }

    
$db->query_write("
        UPDATE " 
TABLE_PREFIX "this_data
        SET sitename = '" 
$db->escape_string($vbulletin->GPC['site_name']) . "',
        siteurl = '" 
$db->escape_string($vbulletin->GPC['site_url']) . "',
        adminemail = '" 
$db->escape_string($vbulletin->GPC['admin_email']) . "'
    "
);

    
define('CP_REDIRECT''testform.php?do=manage');
    
print_stop_message('saved_settings_successfully');

}
// ########################## END FORM UPDATE ############################

// ########################## FORM INSERT ############################ 
print_cp_footer();
?>
I want it to allow you to enter the data, it will be saved and then display that data entered after it is initially submitted. If you change any of the values, and hit save at the bottom, I want it to update the info to the new info.

I thought that what I have written would work, but it doesn't. What did I miss or do incorrectly?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:05 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03971 seconds
  • Memory Usage 2,218KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete