Ik ben nu uren verder maar niets opgeschoten alleen maar foutmeldingen krijg ik. Ik heb tutorials van hier tot en met tokio bekeken maar errors blijven. Bovendien behandelen die tuturials niet meer dan 2 tabellen (niet echt bijster handig dus). Dit is wat ik in elkaar geflanst hebt. IEMAND die mij kan helpen?? In mijn vorige posts heeft ook niemand gereageerd dus ben ik op eigen houtje verder gegaan ik hoop dat nu wel iemand mij verder op weg kan helpen. JAH ik weet mysqlescaptring....dat ga ik nog doen maar het zou prettig zijn als het eindelijk een keer werkt en daar verandert een mysqlescapstring niets aan. EN jah ik heb nu alleen voor zoeken op categorieen in zowel omschrijving als trefwoord (kortom alles) dus ook daar hoeft niet over begonnen te worden. Meer zou het alleen maar complexer maken.

CODE 1: krijg ik volgende error let voornameljk op SQL
Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM afblocatie, afbcategorie, afbomschrijving, afbtrefwoord ' at line 6
In query: SELECT afblocatie.thumbnail, afbcategorie.categorie, afbomschrijving.omschrijving, afbtrefwoord.trefwoord, FROM afblocatie, afbcategorie, afbomschrijving, afbtrefwoord WHERE afblocatie.id = afbtrefwoord.id AND afblocatie.id = afbcategorie.id AND afblocatie.id = afbomschrijving.id AND afblocatie.id = afbtrefwoord.id AND afbcategorie.categorie LIKE 'BVBo7' AND ( afbcategorie.categorie LIKE '`afbtrefwoord.trefwoord` LIKE '%fiets%' ' OR afbcategorie.categorie LIKE '`afbomschrijving.omschrijving` LIKE '%fiets%' ' ) in /home/...../domains/...../public_html/....../geavanceerd_zoeken.php on line 106

CODE:

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once("../../DBconnections/databaseconnectionuploaden.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoeken</title>
</head>

<body>
<!--inputvelden voor gebruiker om te zoeken-->
<form form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
	Zoek op categorie:<br>
	<select name="zoekopcategorie">
        <option value="Bibliotheek">Bibliotheek</option>
        <option value="Conferentie">Conferentie</option>
        <option value="BVBo7">NVB07</option>
        <option value="Onderwijs">Onderwijs</option>
        <option value="Onderzoek">Onderzoek</option>
        <option value="Publicatie">Publicatie</option>
        <option value="Raak project">Raak project</option>
        <option value="Related">Related</option>
        <option value="Site">Site</option>
        <option value="Subsidie">Subsidie</option>
        <option value="Under content creation">Under content creaction</option>
        <option value="Jongeren">Jongeren</option>
        <option value="Zonder categorie">Zonder categorie</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
	in:<br>
	<select name="zoekenin">
		<option value="omschrijving">Omschrijving</option>
		<option value="trefwoord">Trefwoord</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
    Met <b>alle</b> woorden (hoofdlettergevoelig):
	<input name="zoeken" type="text" id="zoeken" size="30"><P>
    <input type="submit" value="zoeken"><P>
</form>

<?php       
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$zoeken = mysql_real_escape_string($_POST['zoeken']);
	$zoekopcategorie = mysql_real_escape_string($_POST['zoekopcategorie']);

//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
if ($_POST['zoekopcategorie'] == 'Bibliotheek' || $_POST['zoekopcategorie'] == 'Conferentie' || $_POST['zoekopcategorie'] == 'BVBo7' || $_POST['zoekopcategorie'] == 'Onderwijs' || $_POST['zoekopcategorie'] == 'Onderzoek' || $_POST['zoekopcategorie'] == 'Publicatie' || $_POST['zoekopcategorie'] == 'Raak project' || $_POST['zoekopcategorie'] == 'Related' || $_POST['zoekopcategorie'] == 'Site' || $_POST['zoekopcategorie'] == 'Subsidie' || $_POST['zoekopcategorie'] == 'Under content creation' || $_POST['zoekopcategorie'] == 'Jongeren' || $_POST['zoekopcategorie'] == 'Zonder categorie' && $_POST['zoekenin'] == 'alles')
		{
//zoeken op alles de ingevoerde zoekwoord mag in 1 of meerdere tabellen voorkomen (zie or regel 60 OR)
			$zoekexploded = explode(' ', $zoeken);
//zorgt ervoor dat de variabelen weer leeg zijn (vooral belangrijk na een al reeds uitgevoerde zoekopdracht
			$like = "";			
			$like2 = "";
			foreach($zoekexploded as $k=>$v) 
			{
				if($k == 0) 
				{
					$like .= "`afbtrefwoord.trefwoord` LIKE '%".$v."%' ";
					$like2 .= "`afbomschrijving.omschrijving` LIKE '%".$v."%' ";
				}
				else
				{
					$like .= "AND `afbtrefwoord.trefwoord` LIKE '%".$v."%' ";
					$like2 .= "AND `afbomschrijving.omschrijving` LIKE '%".$v."%' ";
				}
			}
			$sql = "
			SELECT
				afblocatie.thumbnail,
				afbcategorie.categorie,
				afbomschrijving.omschrijving,
				afbtrefwoord.trefwoord,
			FROM
				afblocatie,
				afbcategorie,
				afbomschrijving,
				afbtrefwoord
			WHERE
				afblocatie.id = afbtrefwoord.id
			AND
				afblocatie.id = afbcategorie.id
			AND
				afblocatie.id = afbomschrijving.id
			AND
				afblocatie.id = afbtrefwoord.id
			AND
				afbcategorie.categorie LIKE '".$zoekopcategorie."'
			AND
				(
					afbcategorie.categorie LIKE '".$like."'
					OR
					afbcategorie.categorie LIKE '".$like2."'
				)
			";
		}
		
	$res = mysql_query($sql);
	
	if(!$res)
	{
		trigger_error(mysql_error().'<br />In query: '.$sql);
	}
	else
	{
		if (mysql_num_rows($res) >= 1)
		{
			while ($row = mysql_fetch_array($res))
			{
//weergave van zoekresultaat
			echo '<p><img src="'.$row['thumbnail'].'" alt="thumbnail" /></p>';
			}
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
		else
		{
			echo "<p>Er is niets gevonden op jou zoekterm:<b> $HTTP_POST_VARS[zoeken]</b></p>";
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
	}
}
?>
</body>
</html>


CODE 2 krijg ik volgende error:
Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM afblocatie INNER JOIN afbtrefwoord ON afblocatie.id = afb' at line 7
In query: SELECT afblocatie.id, afblocatie.thumbnail, afbcategorie.categorie, afbomschrijving.omschrijving, afbtrefwoord.trefwoord, FROM afblocatie INNER JOIN afbtrefwoord ON afblocatie.id = afbtrefwoord.id INNER JOIN afbcategorie ON afblocatie.id = afbcategorie.id INNER JOIN afbomschrijving ON afblocatie.id=afbomschrijving.id WHERE afbcategorie.categorie LIKE 'BVBo7' AND ( afbcategorie.categorie LIKE '`afbtrefwoord.trefwoord` LIKE '%fiets%' ' OR afbcategorie.categorie LIKE '`afbomschrijving.omschrijving` LIKE '%fiets%' ' ) in /home/....../domains/......./public_html/....../geavanceerd_zoeken.php on line 106

CODE:

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once("../../DBconnections/databaseconnectionuploaden.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoeken</title>
</head>

<body>
<!--inputvelden voor gebruiker om te zoeken-->
<form form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
	Zoek op categorie:<br>
	<select name="zoekopcategorie">
        <option value="Bibliotheek">Bibliotheek</option>
        <option value="Conferentie">Conferentie</option>
        <option value="BVBo7">NVB07</option>
        <option value="Onderwijs">Onderwijs</option>
        <option value="Onderzoek">Onderzoek</option>
        <option value="Publicatie">Publicatie</option>
        <option value="Raak project">Raak project</option>
        <option value="Related">Related</option>
        <option value="Site">Site</option>
        <option value="Subsidie">Subsidie</option>
        <option value="Under content creation">Under content creaction</option>
        <option value="Jongeren">Jongeren</option>
        <option value="Zonder categorie">Zonder categorie</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
	in:<br>
	<select name="zoekenin">
		<option value="omschrijving">Omschrijving</option>
		<option value="trefwoord">Trefwoord</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
    Met <b>alle</b> woorden (hoofdlettergevoelig):
	<input name="zoeken" type="text" id="zoeken" size="30"><P>
    <input type="submit" value="zoeken"><P>
</form>

<?php       
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$zoeken = mysql_real_escape_string($_POST['zoeken']);
	$zoekopcategorie = mysql_real_escape_string($_POST['zoekopcategorie']);

//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
if ($_POST['zoekopcategorie'] == 'Bibliotheek' || $_POST['zoekopcategorie'] == 'Conferentie' || $_POST['zoekopcategorie'] == 'BVBo7' || $_POST['zoekopcategorie'] == 'Onderwijs' || $_POST['zoekopcategorie'] == 'Onderzoek' || $_POST['zoekopcategorie'] == 'Publicatie' || $_POST['zoekopcategorie'] == 'Raak project' || $_POST['zoekopcategorie'] == 'Related' || $_POST['zoekopcategorie'] == 'Site' || $_POST['zoekopcategorie'] == 'Subsidie' || $_POST['zoekopcategorie'] == 'Under content creation' || $_POST['zoekopcategorie'] == 'Jongeren' || $_POST['zoekopcategorie'] == 'Zonder categorie' && $_POST['zoekenin'] == 'alles')
		{
//zoeken op alles de ingevoerde zoekwoord mag in 1 of meerdere tabellen voorkomen (zie or regel 60 OR)
			$zoekexploded = explode(' ', $zoeken);
//zorgt ervoor dat de variabelen weer leeg zijn (vooral belangrijk na een al reeds uitgevoerde zoekopdracht
			$like = "";			
			$like2 = "";
			foreach($zoekexploded as $k=>$v) 
			{
				if($k == 0) 
				{
					$like .= "`afbtrefwoord.trefwoord` LIKE '%".$v."%' ";
					$like2 .= "`afbomschrijving.omschrijving` LIKE '%".$v."%' ";
				}
				else
				{
					$like .= "AND `afbtrefwoord.trefwoord` LIKE '%".$v."%' ";
					$like2 .= "AND `afbomschrijving.omschrijving` LIKE '%".$v."%' ";
				}
			}
			$sql = "SELECT
				afblocatie.id,
				afblocatie.thumbnail,
				afbcategorie.categorie,
				afbomschrijving.omschrijving,
				afbtrefwoord.trefwoord,
			FROM
				afblocatie
			INNER JOIN
				afbtrefwoord
			ON
				afblocatie.id = afbtrefwoord.id
			INNER JOIN
				afbcategorie
			ON
				afblocatie.id = afbcategorie.id
			INNER JOIN
				afbomschrijving
			ON
				afblocatie.id=afbomschrijving.id
			WHERE
				afbcategorie.categorie LIKE '".$zoekopcategorie."'
			AND
			(
				afbcategorie.categorie LIKE '".$like."'
				OR
				afbcategorie.categorie LIKE '".$like2."'
			)";
		}
		
	$res = mysql_query($sql);
	
	if(!$res)
	{
		trigger_error(mysql_error().'<br />In query: '.$sql);
	}
	else
	{
		if (mysql_num_rows($res) >= 1)
		{
			while ($row = mysql_fetch_array($res))
			{
//weergave van zoekresultaat
			echo '<p><img src="'.$row['thumbnail'].'" alt="thumbnail" /></p>';
			}
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
		else
		{
			echo "<p>Er is niets gevonden op jou zoekterm:<b> $HTTP_POST_VARS[zoeken]</b></p>";
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
	}
}
?>
</body>
</html>

Dat zie ik maar ik BEGRIJP niet waarom....zou niet moeten kunnen. Zie niet in mijn code waarom het FIETS als kolom wil zien terwijl het een zoekvraag moet zijn in trefwoord en omschrijving....

ook met of zonder die quotes of met deze ' error...ik kan er uren naar kijken maar ontdek de fout niet.
Haal in dit soort regels de backtics weg.
$like .= "AND `afbtrefwoord.trefwoord` LIKE '%".$v."%' ";

En hier een LIKE
afbcategorie.categorie LIKE '".$like."'
kan natuurlijk niet omdat $like een hele string is inclusief kolomnamen.
Ja je doet nu afbcategorie.categorie LIKE 'AND `afbtrefwoord.trefwoord` LIKE '%".$v."%''
` ` weghaald en afbcatregorie.categorie LIKE weggehaald nieuwe error:
Notice: Unknown column 'afbtrefwoord.trefwoord' in 'where clause'
In query: SELECT afblocatie.thumbnail, afbcategorie.categorie, afbomschrijving.omschrijving, afbtrefwoord.trefwoord FROM afblocatie, afbcategorie, afbomschrijving, afbtrefwoord WHERE afblocatie.id = afbtrefwoord.id AND afblocatie.id = afbcategorie.id AND afblocatie.id = afbomschrijving.id AND afblocatie.id = afbtrefwoord.id AND afbcategorie.categorie LIKE 'BVBo7' AND ( `afbtrefwoord.trefwoord` LIKE '%fiets%' OR `afbomschrijving.omschrijving` LIKE '%fiets%' ) in /home/...../domains/....../public_html/...../geavanceerd_zoeken.php on line 106



<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once("../../DBconnections/databaseconnectionuploaden.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoeken</title>
</head>

<body>
<!--inputvelden voor gebruiker om te zoeken-->
<form form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
	Zoek op categorie:<br>
	<select name="zoekopcategorie">
        <option value="Bibliotheek">Bibliotheek</option>
        <option value="Conferentie">Conferentie</option>
        <option value="BVBo7">NVB07</option>
        <option value="Onderwijs">Onderwijs</option>
        <option value="Onderzoek">Onderzoek</option>
        <option value="Publicatie">Publicatie</option>
        <option value="Raak project">Raak project</option>
        <option value="Related">Related</option>
        <option value="Site">Site</option>
        <option value="Subsidie">Subsidie</option>
        <option value="Under content creation">Under content creaction</option>
        <option value="Jongeren">Jongeren</option>
        <option value="Zonder categorie">Zonder categorie</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
	in:<br>
	<select name="zoekenin">
		<option value="omschrijving">Omschrijving</option>
		<option value="trefwoord">Trefwoord</option>
		<option value="alles" selected="selected">alles</option>
	</select><p>
    Met <b>alle</b> woorden (hoofdlettergevoelig):
	<input name="zoeken" type="text" id="zoeken" size="30"><P>
    <input type="submit" value="zoeken"><P>
</form>

<?php       
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	$zoeken = mysql_real_escape_string($_POST['zoeken']);
	$zoekopcategorie = mysql_real_escape_string($_POST['zoekopcategorie']);

//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
//beveiliging zodat andere mensen niet mijn script kunnen gebruiken om in mijn database te komen
if ($_POST['zoekopcategorie'] == 'Bibliotheek' || $_POST['zoekopcategorie'] == 'Conferentie' || $_POST['zoekopcategorie'] == 'BVBo7' || $_POST['zoekopcategorie'] == 'Onderwijs' || $_POST['zoekopcategorie'] == 'Onderzoek' || $_POST['zoekopcategorie'] == 'Publicatie' || $_POST['zoekopcategorie'] == 'Raak project' || $_POST['zoekopcategorie'] == 'Related' || $_POST['zoekopcategorie'] == 'Site' || $_POST['zoekopcategorie'] == 'Subsidie' || $_POST['zoekopcategorie'] == 'Under content creation' || $_POST['zoekopcategorie'] == 'Jongeren' || $_POST['zoekopcategorie'] == 'Zonder categorie' && $_POST['zoekenin'] == 'alles')
		{
//zoeken op alles de ingevoerde zoekwoord mag in 1 of meerdere tabellen voorkomen (zie or regel 60 OR)
			$zoekexploded = explode(' ', $zoeken);
//zorgt ervoor dat de variabelen weer leeg zijn (vooral belangrijk na een al reeds uitgevoerde zoekopdracht
			$like = "";			
			$like2 = "";
			foreach($zoekexploded as $k=>$v) 
			{
				if($k == 0) 
				{
					$like .= "`afbtrefwoord.trefwoord` LIKE '%".$v."%' ";
					$like2 .= "`afbomschrijving.omschrijving` LIKE '%".$v."%' ";
				}
				else
				{
					$like .= "AND afbtrefwoord.trefwoord LIKE '%".$v."%' ";
					$like2 .= "AND afbomschrijving.omschrijving LIKE '%".$v."%' ";
				}
			}
			$sql = "
			SELECT
				afblocatie.thumbnail,
				afbcategorie.categorie,
				afbomschrijving.omschrijving,
				afbtrefwoord.trefwoord
			FROM
				afblocatie,
				afbcategorie,
				afbomschrijving,
				afbtrefwoord
			WHERE
				afblocatie.id = afbtrefwoord.id
			AND
				afblocatie.id = afbcategorie.id
			AND
				afblocatie.id = afbomschrijving.id
			AND
				afblocatie.id = afbtrefwoord.id
			AND
				afbcategorie.categorie LIKE '".$zoekopcategorie."'
			AND
				(
						".$like."
					OR
						".$like2."
				)
			";
		}
		
	$res = mysql_query($sql);
	
	if(!$res)
	{
		trigger_error(mysql_error().'<br />In query: '.$sql);
	}
	else
	{
		if (mysql_num_rows($res) >= 1)
		{
			while ($row = mysql_fetch_array($res))
			{
//weergave van zoekresultaat
			echo '<p><img src="'.$row['thumbnail'].'" alt="thumbnail" /></p>';
			}
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
		else
		{
			echo "<p>Er is niets gevonden op jou zoekterm:<b> $HTTP_POST_VARS[zoeken]</b></p>";
			echo "<p><a href=\"registered_user_area_zoeken.php\" title=\"zoek opnieuw\">zoek opnieuw</a></p>";
		}
	}
}
?>
</body>
</html>
Waarom heb je op regel 63 en 64 '' om je kolomnaam heen. Haal die weg.
laat maar zag nog iets dat fout was. Het was nog een ` Ga het nu testen...en jah het werkt EINDELIJK! Ga nog even intensief testen wel...Allemaal bedankt! Was echt helemaal vastgelopen.

Na uren van frustratie toch wel heerlijk om te zien dat het werkt.

Reageren