Jump to content


Photo

updating 2 differing tables


  • Please log in to reply
5 replies to this topic

#1 dfritter4

dfritter4
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 July 2006 - 03:16 PM

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)

// 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);
			}
		}
	}

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
if( isset($HTTP_POST_VARS['submit']) )
is where it starts to submit to the database

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 July 2006 - 03:40 PM

I'm not really sure why your running that replace to remove escaped quotes; however, it would be hard to run these update statements together, since they're in unrelated tables, AFAIK.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 dfritter4

dfritter4
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 July 2006 - 06:50 PM

but is it possible?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 July 2006 - 08:06 PM

I don't think so... why would you want to, anyway?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 dfritter4

dfritter4
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 July 2006 - 10:06 PM

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.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 July 2006 - 10:12 PM

I understand that, but why try to do it in a single statement?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users