Seite 1 von 1

Probs bei SQL-Abfrage

Verfasst: 07.11.2003 02:35
von andreasOymann
Ich habe folgende Situation:
In Forum 8 stehen Topics mit den Namen A, B, C und D.
In Forum 19 stehen Beiträge mit den Namen B und D.
Nun brauche ich eine Abfrage, die mir einen Link generiert für den Fall, dass in Forum 19 der gleiche topic-title vorhanden ist wie in Forum 8. Dazu habe ich folgendes in der viewtopic.php ergänzt:

Code: Alles auswählen

if ($forum_id == 8)
{
$sql = "SELECT topic_id, topic_title, forum_id
FROM " . TOPICS_TABLE . " 
	WHERE topic_title = $topic_title
		AND forum_id = '19'
		LIMIT 1";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
		}
		if ( $row = $db->sql_fetchrow($result) )
		{
			$linktopic_id = intval($row['topic_id']);
		}		
	if ($linktopic_title != '')
	{
	$template->assign_vars(array(	
		'U_PTB' => append_sid("viewtopic.$phpEx?topic_id=" . $linktopic_id . "&start=$start"),
		'L_PTB' => $lang['Goto_PTB'] . $topic_title)
	);		
	}
}
Funzt aber nicht. Erhalte die Fehlermeldung
SQL Error : 1054 Unbekanntes Tabellenfeld 'B' in where clause.

SELECT topic_id, topic_title, forum_id FROM phpbb_topics WHERE topic_title = B AND forum_id = '19' LIMIT 1
Kann mir da jemand helfen?

A.

Verfasst: 07.11.2003 09:38
von PhilippK
Andreas,

das hier könnte helfen:

Code: Alles auswählen

   WHERE topic_title = '$topic_title'
Gruß, Philipp

Verfasst: 07.11.2003 10:10
von andreasOymann
THX schonmal. Fehlermeldung ist weg.

Abfrage funktioniert leider nicht. Kann nochmal jemand schauen?

A.

Verfasst: 07.11.2003 10:53
von PhilippK
Hast du trim() und str_replace() schon über die $topic_title laufen lassen?

Gruß, Philipp

Verfasst: 07.11.2003 10:54
von andreasOymann
Ne, wie mach ich das?

A.

Verfasst: 07.11.2003 14:31
von PhilippK
Die Frage ist, wo du die $topic_title abgreifst. Die wird nämlich in der posting.php erst mit trim

Code: Alles auswählen

			$subject = ( !empty($HTTP_POST_VARS['subject']) ) ? trim($HTTP_POST_VARS['subject']) : '';
und in der includes/functions_post.php dann mithtmlspecialchars

Code: Alles auswählen

		$subject = htmlspecialchars(trim($subject));
und schließlich in der posting.php nochmals mit str_replace

Code: Alles auswählen

str_replace("\'", "''", $subject)
bearbeitet.

Gruß, Philipp

Verfasst: 07.11.2003 15:38
von andreasOymann
die Variable $topic_title ist in der viewtopic.php schon definiert... ich verlinke einfach mal meine viewtopic.php:

www.retriever-hilfe.de/downloads\viewtopic.php.txt


Wäre schön, wenn du mal schauen könntest!

A.

Verfasst: 07.11.2003 17:00
von PhilippK
Du prüfst die Variable $linktopic_title - der du nirgends einen Wert zuweist. Daher ist sie immer leer und daher wird auch nie was in das Template geschrieben.

Gruß, Philipp

Verfasst: 07.11.2003 18:13
von andreasOymann
oh Mann, bin ich hohl!!! Muss natürlich $linktopic_id heissen.

Vielen Dank!!!

A.