Problema ricerca immagini

sappe

Nuovo Utente
27 Mar 2011
27
0
0
Questa è la mia pagina di ricerca immagine:
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php session_start(); 
?>
<HTML>
<HEAD>
<TITLE>Results</TITLE><link href="style.css" rel="stylesheet" type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<div align="center">
  <TABLE class="maintable" CELLPADDING="0" CELLSPACING="0" summary="">
    <TR> 
      <TD COLSPAN=3> <IMG SRC="images/index_01.gif" WIDTH=727 HEIGHT=240 ALT=""></TD>
    </TR>
    <TR> </div>
      <TD ROWSPAN=2 class="navbg" valign="top"><div id="nav">
          <p><span class="h2">Menu</span> <a href="index.php">Home</a> <a href="rules.php">Rules</a> 
            <a href="gallery.php">Gallery</a> <a href="upload.php">Upload</a> <a href="search.php">Search</a>
             </p>
						
         
					
<?php 
if ((isset($_SESSION['login']))&&((isset($_SESSION['password'])))){
   echo <<<print
	 
	 <p><span class="h2">Logout</span> <a href="profile.php">Your Profile</a> <a href="logout.php">Logout</a><span class="endbox"></span> </p>
         <p><span class="h2">Friendship</span> <a href="users.php">Search user</a> <a href="friend.php">My friends</a> <a href="request.php">Friends request</a> <span class="endbox"></span> </p>
print;
}
else {
   echo <<<print
	 
	 <p><span class="h2">Sign in</span> <a href="create.html">Create account</a> <a href="login.htm">Login</a><span class="endbox"></span></p>
print;
}
 ?>
<?php 
include("connessione.inc");
if (isset($_SESSION['login'])) { 
    $login = $_SESSION['login']; 
$sqlA="SELECT Nickname FROM utenti WHERE Nickname = '$login' AND Admin = '1'";
$resA=mysql_query($sqlA,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($resA);
if ($lines == 1){
 echo <<<print
	 
	 <p><span class="h2">Admin</span> <a href="admin.php">Administration</a><span class="endbox"></span></p>
print;
}
}
echo <<<print

 </p>
        </div></TD>
      <TD ROWSPAN=2 class="contentbg" valign="top"><div id="content">
print;
 ?>
           <h1>Results</h1>
<?php
include("connessione.inc");
if (isset($_GET['search'])){ 
   $search=$_GET['search'];
} 
if (isset ($_POST['title'])!= '') { 
   $nickname = addslashes(htmlentities($_POST['title']));
	 $search = $search."and Title LIKE '%".$title."%' ";
}
if (isset ($_POST['author'])!= '') { 
   $name = addslashes(htmlentities($_POST['author']));
	 $search = $search."and Author LIKE '%".$author."%' ";
}
if (isset ($_POST['tag1'])!= '') { 
   $surname = addslashes(htmlentities($_POST['tag1']));
	 $search = $search."and Tag1 LIKE '%".$tag1."%' ";
}
if (isset ($_POST['tag2'])!= '') { 
   $place = addslashes(htmlentities($_POST['tag2']));
	 $search = $search."and Tag2 LIKE '%".$tag2."%' ";
}
if (isset ($_POST['tag3'])!= '') { 
   $interest1 = addslashes(htmlentities($_POST['tag3']));
	 $search = $search."and Tag3 LIKE '%".$tag3."%' ";
}
if (isset ($_POST['category'])!= '') { 
	 $interest2 = ($_POST['category']);
	 $search = $search."and Category LIKE '%".$category."%' ";
}
if (isset ($_POST['date'])!= '') { 
	 $interest2 = ($_POST['date']);
	 $search = $search."and Date LIKE '%".$date."%' ";
}


$sql="SELECT * FROM (immagini) $search";
$res=mysql_query($sql,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($res);
if ($lines == 0){
   echo "There isn't image with this parameters!";
}
else {
   $recordperpagina=3;//numero di record per pagina
	 $numeropagine=ceil($lines / $recordperpagina);
	 if (isset ($_GET['page'])){ 
	 $paginacorrente = $_GET['page'];
	 }
	    else { 
			$paginacorrente = 1;
	    }
	    $primolimit = ($paginacorrente - 1)* $recordperpagina;

	 $sql="SELECT * FROM (immagini) $search ORDER BY immagini.Title LIMIT $primolimit, $recordperpagina";
   $res=mysql_query($sql,$conn)or die("Error!".mysql_error());
   while ($records=mysql_fetch_assoc($res)) { 
	 $author=$records['Author'];
	 $title=$records['Title'];
	 $tag1=$records['Tag1'];
   $tag2=$records['Tag2'];
   $tag3=$records['Tag3'];
   $category=$records['Category'];
   $date=$records['Date'];
	 $path=$records['Path'];
if ($lines == 1){
 echo <<<MESS
<table summary="lista" id="lista" border="1" cellpadding="4"><tr><td>
<img src="$records[Path]">
</td></tr></table></br>
MESS;
}

}
 
if ($paginacorrente == 1){
						          $precedente = "";
						       }
						       else {
						          $previous_page = ($paginacorrente - 1);
							        $precedente = "<a href=\"?page=$previous_page&search=$search\" title=\"Go to the previous page\" id=\"previus\"><<-- previous</a>";
						       }
						       if($paginacorrente == $numeropagine){
						          $successiva = "";
									 }
									 else {
									    $next_page = ($paginacorrente + 1);
											$successiva = "<a href=\"?page=$next_page&search=$search\" title=\"Go to the next page\" id=\"next\">next -->></a>";
									 }
	                 echo "$precedente <p id=\"paginacorrente\">Page $paginacorrente of $numeropagine </p> $successiva";
}
?> 
          </br>
					</br>
					</br>
					</br>
          <h1>©SketchMania</h1>
      <TD valign="top" class="spacer"></TD>
    </TR><TR> 
      <TD height="2" class="spacer2"></TD>
    </TR><TR> 
      <TD COLSPAN=3 class="creditsbg">
				<p>| Contact us <a href="http://yahoo.com/" target="_blank">[email protected]</a> | </p>
				</TD>
    </TR>
  </TABLE>
</div>
</BODY>
</HTML>
Quando premo submit dalla pagina della form (che è questa):
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php session_start(); 
?>
<HTML>
<HEAD>
<TITLE>Search</TITLE><link href="style.css" rel="stylesheet" type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<div align="center">
  <TABLE class="maintable" CELLPADDING="0" CELLSPACING="0">
    <TR> 
      <TD COLSPAN=3> <IMG SRC="images/index_01.gif" WIDTH=727 HEIGHT=240 ALT=""></TD>
    </TR>
    <TR> 
      <TD ROWSPAN=2 class="navbg" valign="top"><div id="nav">
          <p><span class="h2">Menu</span> <a href="index.php">Home</a> <a href="rules.php">Rules</a> 
            <a href="gallery.php">Gallery</a> <a href="upload.php">Upload</a> <a href="search.php">Search</a>
            <span class="endbox"></span> </p>
						
         
					
<?php 
if ((isset($_SESSION['login']))&&((isset($_SESSION['password'])))){
   echo <<<print
	 
	 <p><span class="h2">Logout</span> <a href="profile.php">Your Profile</a> <a href="logout.php">Logout</a><span class="endbox"></span> </p>
         <p><span class="h2">Friendship</span> <a href="users.php">Search user</a> <a href="friend.php">My friends</a> <a href="request.php">Friends request</a> <span class="endbox"></span> </p>
print;
}
else {
   echo <<<print
	 
	 <p><span class="h2">Sign in</span> <a href="create.html">Create account</a> <a href="login.htm">Login</a><span class="endbox"></span></p>
print;
}
 ?>
<?php 
include("connessione.inc");
if (isset($_SESSION['login'])) { 
    $login = $_SESSION['login']; 
$sqlA="SELECT Nickname FROM utenti WHERE Nickname = '$login' AND Admin = '1'";
$resA=mysql_query($sqlA,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($resA);
if ($lines == 1){
 echo <<<print
	 
	 <p><span class="h2">Admin</span> <a href="admin.php">Administration</a><span class="endbox"></span></p>
print;
}
}
echo <<<print

 </p>
        </div></TD>
      <TD ROWSPAN=2 class="contentbg" valign="top"><div id="content">
print;
 ?>

          <h1>Search</h1>
<FORM name="search" action="searchImage.php" METHOD=POST>
<b>Title</b>
Write the title:<br>
<INPUT type=text name="title">
</br>
	<fieldset> 
<legend><b>Author</b></legend>
  <label>Write the author:<br>
     <INPUT type=text name="author">
  </label></fieldset></br>
<fieldset>
<legend><b>Select the tags</b> (max 3 tags):</legend><label>
<input name="tag1" type="text" size="20" maxlength="30"></br>
<input name="tag2" type="text" size="20" maxlength="30"></br>
<input name="tag3" type="text" size="20" maxlength="30"></label>
	 </fieldset></br>
<fieldset>
 <legend><b>Select category</b></legend>
 <input type="radio" name="category" value="nature" checked="checked"/>Nature
 <input type="radio" name="category" value="people"/>People 
 <br>
 <input type="radio" name="category" value="animal"/>Animal
 <input type="radio" name="category" value="other"/>Other
</fieldset>
	</br>
 <fieldset>
  <legend>Date</legend>
<select name="day" >
   <option value="one" selected="selected">1</option>
   <option value="two">2</option>
   <option value="three">3</option>
	 <option value="four">4</option>
	 <option value="five">5</option>
	 <option value="six">6</option>
	 <option value="seven">7</option>
	 <option value="eight">8</option>
	 <option value="nine">9</option>
	 <option value="ten">10</option>
	 <option value="eleven">11</option>
	 <option value="twelve">12</option>
	 <option value="thirteen">13</option>
	 <option value="fourteen">14</option>
	 <option value="fifteen">15</option>
	 <option value="sixteen">16</option>
	 <option value="seventeen">17</option>
	 <option value="eighteen">18</option>
	 <option value="nineteen">19</option>
	 <option value="twenty">20</option>
	 <option value="twentyone">21</option>
	 <option value="twentytwo">22</option>
	 <option value="twentythree">23</option>
	 <option value="twentyfour">24</option>
	 <option value="twentyfive">25</option>
	 <option value="twentysix">26</option>
	 <option value="twentyseven">27</option>
	 <option value="twentyeight">28</option>
	 <option value="twentynine">29</option>
	 <option value="thirty">30</option>
	 <option value="thirtyone">31</option>
  </select>
	 <select name="month" >
   <option value="january" selected="selected">January</option>
   <option value="february">February</option>
   <option value="march">March</option>
	 <option value="april">April</option>
   <option value="may">May</option>
   <option value="june">June</option>
   <option value="july">July</option>
   <option value="august">August</option>
   <option value="september">September</option>
   <option value="october">October</option>
   <option value="november">November</option>
   <option value="december">December</option>
  </select>
	<select name="year" >
   <option value="twothousand" selected="selected">2010</option>
   <option value="twothousandandeleven">2011</option>
   <option value="twothousandandtwelve">2012</option>
  </select>
 </fieldset>

<div align="center"><button type="submit">
   submit
 </button></div></br></form> 
					</p>
          </br>
					</br>
					</br>
					</br>
          <h1>©SketchMania</h1>
      <TD valign="top" class="spacer"></TD>
    </TR><TR> 
      <TD height="2" class="spacer2"></TD>
    </TR><TR> 
      <TD COLSPAN=3 class="creditsbg">
				<p>| Contact us <a href="http://yahoo.com/" target="_blank">[email protected]</a> | </p></TD>
    </TR>
  </TABLE>
</div>
</BODY>
</HTML>
Mi esce questa serie di errori:
PHP:
Notice: Undefined variable: search in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 67

Notice: Undefined variable: title in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 67

Notice: Undefined variable: author in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 71

Notice: Undefined variable: tag1 in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 75

Notice: Undefined variable: tag2 in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 79

Notice: Undefined variable: tag3 in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 83

Notice: Undefined variable: category in C:\Program Files\EasyPHP-5.3.2\www\Sito\searchImage.php on line 87
Error!Errore di sintassi nella query SQL vicino a 'and Title LIKE '%%' and Author LIKE '%%' and Tag1 LIKE '%%' and Tag2 LIKE '%%' a' linea 1
Il problema è... Che non capisco assolutamente cosa sto sbagliando! :(
Qualcuno è in grado di aiutarmi? Grazie infinite in anticipo, anche per la pazienza!!
 

sappe

Nuovo Utente
27 Mar 2011
27
0
0
Prova ad aggiungere questo:
PHP:
$search = '';
Dopo:
PHP:
include("connessione.inc");
Grazie della risposta! :D Ho provato ad applicare questo metodo per tutte le variabili che mi davano errore e il messaggio è sparito, però continua a darmi:
PHP:
Error!Errore di sintassi nella query SQL vicino a 'and Title LIKE '%%' and Author LIKE '%%' and Tag1 LIKE '%%' and Tag2 LIKE '%%' a' linea 1
non capisco proprio come si risolve! :(
EDIT:
ho risolto la pagina:
PHP:
<?php
include("connessione.inc");

$search="WHERE (State = '1')";
if (isset($_GET['search'])){ 
   $search=$_GET['search'];
} 
if (isset ($_POST['title'])!= '') { 
   $title = addslashes(htmlentities($_POST['title']));
	 $search = $search."and Title LIKE '%".$title."%' ";
}
if (isset ($_POST['nickname'])!= ''){
$nickname=$_POST['nickname'];
$sql="SELECT IDutente FROM utenti WHERE Nickname LIKE '$nickname'";
$res=mysql_query($sql,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($res);
while ($records=mysql_fetch_assoc($res)) { 
$IDuser=$records['IDutente'];
}
if ($lines == 1){
   $search = $search."and Author LIKE '%".$IDuser."%' ";
   }
}


if (isset ($_POST['tag1'])!= '') { 
   $tag1 = addslashes(htmlentities($_POST['tag1']));
	 $search = $search."and Tag1 LIKE '%".$tag1."%' ";
}
if (isset ($_POST['tag2'])!= '') { 
   $tag2 = addslashes(htmlentities($_POST['tag2']));
	 $search = $search."and Tag2 LIKE '%".$tag2."%' ";
}
if (isset ($_POST['tag3'])!= '') { 
   $tag3 = addslashes(htmlentities($_POST['tag3']));
	 $search = $search."and Tag3 LIKE '%".$tag3."%' ";
}
if (isset ($_POST['category'])!= '') { 
	 $category = ($_POST['category']);
	 $search = $search."and Category LIKE '%".$category."%' ";
}
if (isset ($_POST['date'])!= '') { 
	 $date = ($_POST['date']);
	 $search = $search."and Date LIKE '%".$date."%' ";
}
$sql="SELECT * FROM (immagini) $search";
$res=mysql_query($sql,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($res);
if ($lines == 0){
   echo "There isn't image with this parameters! $search";
}
   $recordperpagina=3;//numero di record per pagina
	 $numeropagine=ceil($lines / $recordperpagina);
	 if (isset ($_GET['page'])){ 
	 $paginacorrente = $_GET['page'];
	 }
	    else { 
			$paginacorrente = 1;
	    }
	    $primolimit = ($paginacorrente - 1)* $recordperpagina;

   $sql="SELECT * FROM immagini JOIN utenti ON immagini.Author = utenti.IDutente $search ORDER BY immagini.Title LIMIT $primolimit, $recordperpagina";
   $res=mysql_query($sql,$conn)or die("Error!".mysql_error());
   while ($records=mysql_fetch_assoc($res)) { 
	 $ID=$records['IDsketch'];
	 $nickname=$records['Nickname'];
	 $title=$records['Title'];
	 $tag1=$records['Tag1'];
   $tag2=$records['Tag2'];
   $tag3=$records['Tag3'];
   $category=$records['Category'];
   $date=$records['Date'];
	 $path=$records['Path'];
	 $description=$records['Descrizione'];
if ($lines >= 1){
 echo <<<MESS
<table summary="imageSearch" border="1" id="image">
<tr align="center"><td>
<a href="image.php?path=$path&title=$title&nickname=$nickname&tag1=$tag1&tag2=$tag2&tag3=$tag3&category=$category&description=$description&ID=$ID">
<img src="$records[Path]" style="width: 40%"></a></td></tr>
<tr><td>by $nickname</td></tr>
<tr><td>$title</tr></td>
</table></br>
MESS;
}  
}




if ($paginacorrente == 1){
						          $precedente = "";
						       }
						       else {
						          $previous_page = ($paginacorrente - 1);
							        $precedente = "<a href=\"?page=$previous_page&search=$search\" title=\"Go to the previous page\" id=\"previus\"><<-- previous</a>";
						       }
						       if($paginacorrente == $numeropagine){
						          $successiva = "";
									 }
									 else {
									    $next_page = ($paginacorrente + 1);
											$successiva = "<a href=\"?page=$next_page&search=$search\" title=\"Go to the next page\" id=\"next\">next -->></a>";
									 }
	                 echo "$precedente <p id=\"paginacorrente\">Page $paginacorrente of $numeropagine </p> $successiva";

?>
per i posteri :D
I moderatori possono chiudere la discussione
 
Ultima modifica:
Discussioni simili
Autore Titolo Forum Risposte Data
R Problema query con ricerca id numerico PHP 2
E Problema motore di ricerca FULL_TEXT PHP 0
T4MAR4 [PHP] Problema ricerca con apostrofo PHP 2
A [PHP] Problema paginazione motore di ricerca PHP 48
P Problema non mi esegue la ricerca dati PHP 23
M Problema con ricerca full-text PHP 1
elpirata Query di ricerca problema campo data italiano PHP 2
M Problema checkbox e ricerca avanzata PHP 8
L Problema META NAME description [MOTORE RICERCA] HTML e CSS 0
Sargon Motore di ricerca, nuovo problema PHP 3
G Problema nella pagine dei risultati ricerca Wordpress WordPress 2
G Php problema con risultato di ricerca PHP 2
K Problema ricerca con piu campi in php PHP 3
A problema con l'inserimento di valori in una tabella dopo una ricerca da form Classic ASP 1
R Problema nel $_POST di dati per ricerca su DB PHP 12
Emix Problema ricerca in database PHP 20
O Problema APICI con la ricerca PHP 2
G Problema ricerca codice PHP 2
L problema pagina di ricerca PHP 2
M Problema motore di ricerca Javascript 1
M problema ricerca su più tabelle. PHP 1
C problema con Referer e Motori di ricerca SEO e Posizionamento 1
S Problema motore di ricerca in Asp Classic ASP 2
F NetBeans problema creazione progetto Java Windows e Software 0
M Problema con Try Catch PHP 0
C problema seo + cerco esperto SEO e Posizionamento 1
Sergio Unia Problema con gli eventi del mouse su una data table: Javascript 2
T PROBLEMA CON SESSIONI PHP 3
A Problema, non so, di scale() o transform, oppure altro? HTML e CSS 0
T ALTRO PROBLEMA CON ARRAY PHP PHP 1
T PROBLEMA CON ARRAY PHP 8
L problema con query select PHP 2
F Problema con risposta PHP 0
S problema con recupero dati tabella mysql PHP 2
Z Problema con il mio tp-l i nk Reti LAN e Wireless 1
I PROBLEMA: Sostituzione sito XAMPP E-Commerce 0
T problema data 30/11/-1 PHP 0
L Problema RAM con Tomcat 8 Apache 0
napuleone problema con sort e asort PHP 4
Y Problema incolonnamento tabella PHP 7
S problema salvataggio immagini Photoshop 0
Z Problema con INT MySQL PHP 1
Z Problema database MySQL con XAMPP PHP 0
M Problema con controllo form in real time jQuery 6
D problema php mysql PHP 1
D problema php mysql PHP 1
M Problema Wi-Fi Linux Linux e Software 1
Z Problema di sincronizzazione PAYPAL con PHP PHP 1
Daniele_Carrara Problema Aperture Mailup Email Marketing 5
F PROBLEMA ACCESSO INSTAGRAM Discussioni Varie 2

Discussioni simili