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>