Jump to content

updating 2 differing tables


dfritter4

Recommended Posts

im working with phpBB forums and doing some mods to it.

at one point in my code, i need to go from updating one table in the database, to two different tables

here is where its submitting the information to the database: (my code is between the // random quote mod)

[code]// random quotes mod
$sqldata = "SELECT *
FROM " . QUOTES_TABLE;
if(!$result = $db->sql_query($sqldata))
{
message_die(CRITICAL_ERROR, "Could not query quotes information in admin_board", "", __LINE__, __FILE__, $sqldata);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$quotes_name = $row['quotes_name'];
$quotes_value = $row['quotes_value'];
$default_quotes[$quotes_name] = isset($HTTP_POST_VARS['submit']) ? str_replace("'", "\'", $quotes_value) : $quotes_value;

$quotes[$quotes_name] = ( isset($HTTP_POST_VARS[$quotes_name]) ) ? $HTTP_POST_VARS[$quotes_name] : $default_quotes[$quotes_name];
}
}
// random quotes mod

//
// Pull all config data
//
$sql = "SELECT *
FROM " . CONFIG_TABLE;
if(!$result = $db->sql_query($sql))
{
message_die(CRITICAL_ERROR, "Could not query config information in admin_board", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$config_name = $row['config_name'];
$config_value = $row['config_value'];
$default_config[$config_name] = isset($HTTP_POST_VARS['submit']) ? str_replace("'", "\'", $config_value) : $config_value;

$new[$config_name] = ( isset($HTTP_POST_VARS[$config_name]) ) ? $HTTP_POST_VARS[$config_name] : $default_config[$config_name];

if ($config_name == 'cookie_name')
{
$new['cookie_name'] = str_replace('.', '_', $new['cookie_name']);
}



// Attempt to prevent a common mistake with this value,
// http:// is the protocol and not part of the server name
if ($config_name == 'server_name')
{
$new['server_name'] = str_replace('http://', '', $new['server_name']);
}

if( isset($HTTP_POST_VARS['submit']) )
{
$sql = "UPDATE " . CONFIG_TABLE . " SET
config_value = '" . str_replace("\'", "''", $new[$config_name]) . "'
WHERE config_name = '$config_name'";
//random quotes mod
$sqldata = "UPDATE " . QUOTES_TABLE . " SET
quotes_value = '" . str_replace("\'", "''", $quotes[$quotes_name]) . "'
WHERE quotes_name = '$quotes_name'";
// random quotes mod
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update general configuration for $config_name", "", __LINE__, __FILE__, $sql);
}
if( !$db->sql_query($sqldata) )
{
message_die(GENERAL_ERROR, "Failed to update random header quotes for $quotes_name", "", __LINE__, __FILE__, $sqldata);
}
}
}[/code]

now it is reading the info from the database for the CONFIG_TABLE but when you press submit to update any changed information, it just brings up the old data (it never updates it)

theres obviously something wrong with the way ive done this, and i was hoping someone could tell me how to make sure both the CONFIG_TABLE and the QUOTES_TABLE were updated in that one pass.

the [code]if( isset($HTTP_POST_VARS['submit']) )[/code] is where it starts to submit to the database
Link to comment
Share on other sites

because the data type for the config_value field is a varchar(255) and the text im going to need to store in the database is going to be a very very very long string. and id have to either create a new database table and store it there, or change the data type of the config_value field to a longtext type. and the people that are going to be validating my mod might not like me changing a default datatype for a configuration table.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.