Need help: I want to update a column in database ...

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Need help: I want to update a column in database ...

Post by Dugi » Thu Oct 14, 2010 3:49 pm

My question is quite simple, but I cannot find the answer for it...

I have a <input type="text" name="submitted_amount" id="submitted_amount" value="10" />

This is part of the prosilver template and I named it confirm_body.html and I can call it via confirm.php (simple template code), and I want to store the value 10 in my database record named submitted_amount. So, in a way, a normal user would be able to change/update the value in the database. How is this possible :?:

If you need more clarifications, please ask, I'll try to explain as detailed as possible.
Last edited by Dugi on Thu Oct 14, 2010 9:43 pm, edited 1 time in total.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Need help: I want to record a value in database...

Post by hah » Thu Oct 14, 2010 5:20 pm

Here is some example.

CREATE TABLE phpbb_table (submitted_amount varchar(255) NOT NULL);

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
	
global $auth, $cache, $config, $user, $db, $phpbb_root_path, $phpEx, $template;

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if(!$user->data['is_registered']) { login_box("","Please login to submit this amount"); }

$submitted_amount = $_POST['submitted_amount'];
$submitted_amount = addslashes($submitted_amount);
if($submitted_amount) {
$sql = ("INSERT INTO phpbb_table (submitted_amount) VALUE ('$submitted_amount')");
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
trigger_error("Amount was submitted to the database");
}
else {
trigger_error("Amount not set");
}

?>

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to record a value in database...

Post by Dugi » Thu Oct 14, 2010 6:41 pm

This doesn't seem to work for me :roll:
PM me for custom extension pricing / My validated MODs / My MODs in development

Marc Bonnier
Registered User
Posts: 4
Joined: Thu Oct 14, 2010 8:29 pm

Re: Need help: I want to update a column in database ...

Post by Marc Bonnier » Thu Oct 14, 2010 9:50 pm

Dugi wrote:My question is quite simple, but I cannot find the answer for it...

I have a <input type="text" name="submitted_amount" id="submitted_amount" value="10" />

This is part of the prosilver template and I named it confirm_body.html and I can call it via confirm.php (simple template code), and I want to store the value 10 in my database record named submitted_amount. So, in a way, a normal user would be able to change/update the value in the database. How is this possible :?:

If you need more clarifications, please ask, I'll try to explain as detailed as possible.
In not sure I get it. You want to add a function to allow your user to change a value that is set to 10 by default?

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Thu Oct 14, 2010 10:35 pm

Marc Bonnier wrote:
Dugi wrote:My question is quite simple, but I cannot find the answer for it...

I have a <input type="text" name="submitted_amount" id="submitted_amount" value="10" />

This is part of the prosilver template and I named it confirm_body.html and I can call it via confirm.php (simple template code), and I want to store the value 10 in my database record named submitted_amount. So, in a way, a normal user would be able to change/update the value in the database. How is this possible :?:

If you need more clarifications, please ask, I'll try to explain as detailed as possible.
In not sure I get it. You want to add a function to allow your user to change a value that is set to 10 by default?
Exactly, in a way the user would be able to "update" the database column named submitted_amount to the value he/she entered in the text field.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Fri Oct 15, 2010 8:35 am

BUMP.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Need help: I want to update a column in database ...

Post by hah » Fri Oct 15, 2010 4:59 pm

$sql = ("UPDATE phpbb_table SET submitted_amount = '$submitted_amount'");

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Fri Oct 15, 2010 6:13 pm

What you said is just cleaning up the column in the database, it get's empty after executing the SQL, but doesn't grab anything from the <input>
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Need help: I want to update a column in database ...

Post by hah » Fri Oct 15, 2010 7:33 pm

Dugi wrote:What you said is just cleaning up the column in the database, it get's empty after executing the SQL, but doesn't grab anything from the <input>
Well, can't you just set it up? I made it with $_POST['submitted_amount']; if its other just change it, that you can't replace a simple text, doesn't mean that the code doesn't work..

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Fri Oct 15, 2010 8:20 pm

I'll show you how my code looks like, so you can tell me what I'm doing wrong...

donate/index.php

Code: Select all

<?php
/**
/*
* @package - Donation MOD
* @version 1.0b5
* @copyright 2010 (c) Dugi.
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$current_dir = './';
$phpbb_root_path = $current_dir . '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/donation_mod');
	
function submitted_amount()
{
	global $db, $user, $auth, $template, $config;
	global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
	
		include ($phpbb_root_path . 'includes/functions_user.' . $phpEx);
		include ($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
		include_once ($phpbb_root_path . 'donate/functions_donate.' . $phpEx);
	
		$submit = (isset($_POST['submitted_amount'])) ? true : false;
		$form_key	= 'postform';
		add_form_key($form_key);
				
		$sql = 'UPDATE ' . DONATION_TABLE . "
				SET config_value = '" . $submit . "'
				WHERE config_name = 'submitted_amount'";
			
		$result = $db->sql_query($sql);
}

page_header($user->lang['DONATE_EXPLAIN'], false);

submitted_amount();

$template->set_filenames(array(
	'body' => 'donate/index_body.html')
);

page_footer();

?>
styles/prosilver/template/donate/index_body.html

Code: Select all

<!-- INCLUDE overall_header.html -->
<!-- IF S_DONATE_ENABLE -->
<!-- IF S_DONATE_ENABLE_REGS and not (S_USER_LOGGED_IN) -->
 <div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>
	<h2>{L_INFORMATION}</h2>
        <fieldset class="fields2">
            <span class="style1"><p>{L_DONATE_REGISTER_MSG}<br /><br /><a href="{U_REGISTER}">{L_DONATE_REG_REDIRECT}</a></p></div>
        </fieldset>
	<span class="corners-bottom"><span></span></span><div></div>
</div>
<!-- ELSE -->
<form name="postform" id="postform" action="{U_DONATE_CONFIRM}" method="post">               
    <div class="panel">
        <div class="inner"><span class="corners-top"><span></span></span>
            <h2>{L_DONATE_TO} {SITENAME}</h2>
            <dl>
            	<dt><span class="style3">{L_HELLO} <b>{S_USERNAME}</b>,</span></dt><br/>
           	 	<dt><span class="style3">{S_DONATE_MESSAGE}</span></dt>
            </dl>			
            <hr /><br/>
              <dl>
            	<label for="submitted_amount"><span class="font">{L_DONATE_AMOUNT}</span></label>{L_WHITE_SPACE}
                <input type='text' name='submitted_amount' id='submitted_amount' value='' size="25" tabindex="1" maxlength='9' class='inputbox_d' align="top"> <strong>{S_DONATE_CURRENCY}</strong>
                <br/><br/>
              </dl>
        <span class="corners-bottom"><span></span></span></div>
    	</div>
        <div class="panel">
            <div class="inner"><span class="corners-top"><span></span></span>         
                <fieldset class="submit-buttons">
                    <center>
                    <input type='reset' class="button2" name='submit' value='{L_RESET}'>
                    <input type='submit' class="button1" name='submit' value='{L_SUBMIT}'>
                    </center>
                </fieldset>
                </form>
                <span class="corners-bottom"><span></span></span>
			</div>
	</div>
<!-- ENDIF -->
<!-- ELSE -->
<div class="panel">
  <div class="inner"><span class="corners-top"><span></span></span>
	<h2>{L_INFORMATION}</h2>
        <fieldset class="fields2">
            <span class="style1"><p>{L_DONATE_DISABLED}<br /><br /><a href="{U_INDEX}">{L_DONATE_INDEX_RETURN}</a></p></div>
        </fieldset>
	<span class="corners-bottom"><span></span></span><div></div>
</div>
<!-- ENDIF -->
<!-- INCLUDE donate/overall_footer_donate.html -->
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Need help: I want to update a column in database ...

Post by hah » Sat Oct 16, 2010 8:46 am

WHERE config_name = 'submitted_amount'";
should be
WHERE config_name = '$submitted_amount'";

The config_name has missing variable $.

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Sat Oct 16, 2010 8:59 am

The name of the config in the database IS submitted_amount, I only need to change it;s config_value to the entered number, which I'm not able to get.
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
hah
Registered User
Posts: 85
Joined: Sat Feb 13, 2010 11:49 am
Location: Pernik, Bulgaria
Name: Alex Georgiev
Contact:

Re: Need help: I want to update a column in database ...

Post by hah » Sat Oct 16, 2010 9:20 am

Code: Select all

    <?php
    /**
    /*
    * @package - Donation MOD
    * @version 1.0b5
    * @copyright 2010 (c) Dugi.
    * @license http://opensource.org/licenses/gpl-license.php GNU Public License
    *
    */

    /**
    * @ignore
    */
    define('IN_PHPBB', true);
    $current_dir = './';
    $phpbb_root_path = $current_dir . '../';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup('mods/donation_mod');
       
    function submitted_amount()
    {
       global $db, $user, $auth, $template, $config;
       global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
       
          include ($phpbb_root_path . 'includes/functions_user.' . $phpEx);
          include ($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
          include_once ($phpbb_root_path . 'donate/functions_donate.' . $phpEx);
       
          $submit = (isset($_POST['submitted_amount'])) ? true : false;
          $form_key   = 'postform';
          add_form_key($form_key);
                
          $sql = 'UPDATE ' . DONATION_TABLE . "
                SET config_value = '" . $submit . "'
                WHERE config_name = 'submitted_amount'";
             
          $result = $db->sql_query($sql);
          $db->sql_freeresult($result);
    }

    page_header($user->lang['DONATE_EXPLAIN'], false);

    submitted_amount();

    $template->set_filenames(array(
       'body' => 'donate/index_body.html')
    );

    page_footer();

    ?>

User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm
Location: Mainz, Germany
Name: Dukagjin Surdulli
Contact:

Re: Need help: I want to update a column in database ...

Post by Dugi » Sat Oct 16, 2010 12:58 pm

Doesn't work. Something else?
PM me for custom extension pricing / My validated MODs / My MODs in development

User avatar
imkingdavid
Former Team Member
Posts: 2667
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Need help: I want to update a column in database ...

Post by imkingdavid » Sat Oct 16, 2010 1:00 pm

Try the following.

First of all, I don't see the point of having the code in a function when you're only calling that function in the same file. Unless you condensed it for putting it here and this isn't how it actually is, then you might want to try the following.

Code: Select all

<?php
/**
/*
* @package - Donation MOD
* @version 1.0b5
* @copyright 2010 (c) Dugi & [ND], uImg.
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$current_dir = './';
$phpbb_root_path = $current_dir . '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/donation_mod');
    
include ($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include ($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include_once ($phpbb_root_path . 'donate/functions_donate.' . $phpEx);

$submit = (isset($_POST['submit'])) ? true : false;
$submitted_amount = request_var('submitted_amount', 0);

if($submit)
{
    $sql = 'UPDATE ' . DONATION_TABLE . '
            SET config_value = ' . (int) $submitted_amount . '
            WHERE config_name = \'submitted_amount\'';

    $result = $db->sql_query($sql);
}

page_header($user->lang['DONATE_EXPLAIN'], false);

$template->set_filenames(array(
    'body' => donate/index_body.html)
);

page_footer();

?>
Although, is this to store a user's donation? If so, why are you using a config value?
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Locked

Return to “[3.0.x] MOD Writers Discussion”