I have a CMS, an Intranet for my teammates, we are working every day on this intranet.
We have a team list page, with different access for each teammate.
For go finishing the intro, We too have, an update.php page, that the page, is executed automaticaly when a teammate was promoted or relegated.

When I had drupal 6, the script was worked always, as good as We needed.

But when We upgrade drupal from version 6 to version 7, the script works today, but the changes on the database, Are not reflected on the website.

How I can update the content of a specific page, from the database?

The update.php page:

<?php
if ($_POST['pass'] != "*********")
 die ("Stop It now!");
$pre = "<b>Oficial page with the list of team members</b>.\n<!--break-->\n";
$pre .= $_POST['html'];
$cnx = mysql_connect("localhost", "na*****_h***", "*********") or DIE(mysql_error());
mysql_select_db("na*****_h***", $cnx);
   if(get_magic_quotes_gpc())  
   {  
   $pre = stripslashes($pre);  
   }     
   // a mySQL connection is required before using this function  
   $data = mysql_real_escape_string($pre);
mysql_query ("UPDATE home_field_revision_body SET body_value='$data' WHERE entity_id='5'");
echo "Actualizado correctamente";
mysql_close($cnx);
?>

Comments

Jaypan’s picture

There are all sorts of problems with that script. It's entirely not Drupal. It uses $_POST data (which we don't use in Drupal). It's bypassing the Database API and using msyql database functions. And it's directly outputting data rather than using Drupal's API to create messages.

I don't think you'll find a lot of help here, as people here generally give Drupal assistance, and that script isn't Drupal.

dp07Daniel’s picture

Seeing your answer... I am changing the method of do it... Now I create a module natasha_team and I am testing with this code:

<?php
/**
 * @file
 * Un modulo ue promete actualizar prediódicamente la lista de teamlers de Natasha BOT
 *
 * @param path
 *   Which path of the site we're using to display help
 * @param arg
 *   Array that holds the current path as returned from arg() function
 */
function natasha_team_help($path, $arg) {
  switch ($path) {
    case "admin/help#natasha_team":
      return '<p>' . t("Actualiza la lista de teamlers de Natasha") . '</p>';
      break;
  }
}
function natasha_team_cron() {
  // codigo php para obtener la info nueva;
  $node = node_load(5);
  $node->body = 'probando';
  node_save($node);
}

But when the cron is executing, I have this error line:

Notice: Trying to get property of non-object en search_index() (línea 640 de /home1/natasha/public_html/home/modules/search/search.module).

Jaypan’s picture

In Drupal 7, this doesn't exist:

  $node->body = 'probando';

You'll need to examine an existing node to get the path to the body field. I can't remember what it is off the top of my head, but in D7, it's a field (known as CCK in D6), so the path is something like:

$node->body_field[LANGUAGE_NONE][0]['value'];

Note two things:
1) If you see 'und' in the path to a value, it should be written as LANGUAGE_NONE in your code, like I have done above.
2) This thread should be moved to the Module Development and Code Questions section of the forum. You can move it by editing the original post and choosing that section as the forum.

Thank you.

dp07Daniel’s picture

Well... I am continue to trying to solve this question. I use your code "$node->body_field[LANGUAGE_NONE][0]['value'];" but the error, continue.

Code that I am using now:

function natasha_team_cron() {
  // codigo php para obtener la info nueva;
  $node = node_load(5);
  $node->body_field[LANGUAGE_NONE][0]['value'] = 'probando';
  node_save($node);
}

Error message that I receive when the cron is executed:

Notice: Trying to get property of non-object en search_index() (línea 640 de /home1/natasha/public_html/home/modules/search/search.module).

Certainly, I will continue to seek on drupal, the right way to use the API and edit the content of the page. But I am open to receive other answers. Thank you so much.

Jaypan’s picture

As I said, you'll need to examine an existing node to find out the actual path to the body field - I just gave an example, I didn't (and don't) think it is correct. I was just giving you the overall idea on how to do it.

dp07Daniel’s picture

I can't understand how can I find the really path.

Can you help me again?

WorldFallz’s picture

output $node either using dpm (if you use the devel module, highly recommended) or print_r if you don't.

dp07Daniel’s picture

Well... Now I have the full path. But..... It doesn't work.... Please, see the path:

stdClass Object (
	[vid] => 6
	[uid] => 1
	[title] => Este es el equipo.
	[log] =>
	[status] => 1
	[comment] => 1
	[promote] => 0
	[sticky] => 0
	[nid] => 5
	[type] => page
	[language] => es
	[created] => 1397532615
	[changed] => 1397670113
	[tnid] => 0
	[translate] => 0
	[revision_timestamp] => 1397670113
	[revision_uid] => 0
	[body] => Array (
		[und] => Array (
			[0] => Array (
				[value] => Página Oficial del Team de Natasha-Bot
				[safe_summary] =>
			)
		)
	)
	[rdf_mapping] => Array (
		[rdftype] => Array (
			[0] => foaf:Document
		)
		[title] => Array (
			[predicates] => Array (
				[0] => dc:title
			)
		)
		[created] => Array (
			[predicates] => Array (
				[0] => dc:date
				[1] => dc:created
			)
			[datatype] => xsd:dateTime
			[callback] => date_iso8601
		)
		[changed] => Array (
			[predicates] => Array (
				[0] => dc:modified
			)
			[datatype] => xsd:dateTime
			[callback] => date_iso8601
		)
		[body] => Array (
			[predicates] => Array (
				[0] => content:encoded
			)
		)
		[uid] => Array (
			[predicates] => Array (
				[0] => sioc:has_creator
			)
			[type] => rel
		)
		[name] => Array (
			[predicates] => Array (
				[0] => foaf:name
			)
		)
		[comment_count] => Array (
			[predicates] => Array (
				[0] => sioc:num_replies
			)
			[datatype] => xsd:integer
		)
		[last_activity] => Array (
			[predicates] => Array (
				[0] => sioc:last_activity_date
			)
			[datatype] => xsd:dateTime
			[callback] => date_iso8601
		)
	)
	[cid] => 0
	[last_comment_timestamp] => 1397532615
	[last_comment_name] =>
	[last_comment_uid] => 1
	[comment_count] => 0
	[name] => Natasha
	[picture] => 0
	[data] => b:0;
)
[body] => Array (
[und] => Array (
[0] => Array (
[value] => Página Oficial del Team de Natasha-Bot
[safe_summary] =>
)
)
)

The thing is, if i use this: $node->body_field['und'][0]['value'] = 'foo';

Nothing Changes...

@Edit: I am using: $node->body['und'][0]['value'] = 'foo'; <-- And It works so good!!! Thank you SO MUCH to all of users that help to me.

Jaypan’s picture

Glad it worked. Note that you should use this instead:

$node->body[LANGUAGE_NONE][0]['value'] = 'foo';