2011-10-26 2 views
0

저는 온라인에서 발견 된 검색 스크립트가 있지만 문제가있는 것으로 보입니다. '다음'링크를 클릭해도 아무 일도 일어나지 않지만 '정의되지 않은 변수 : PHP_SELF'오류가 발생합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? help.The 코드는 다음과 같습니다하시기 바랍니다 :검색 스크립트 페이지 매김이 작동하지 않습니다.

print "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?s=$prevs&q=$var\">&lt;&lt; Prev 10</a>&nbsp&nbsp;"; 

은 또한 당신의 코드에서 몇 가지 문제가있다 :

<head> 
    <title>Search pegination</title> 
    <meta name="author" content="Steve R, http://www.designplace.org/"> 
    </head> 
    <body> 

    <form name="form" action="search.php" method="get"> 
     <input type="text" name="q" /> 
     <input type="submit" name="Submit" value="Search" /> 
    </form> 

    <?php 

     // Get the search variable from URL 

     $var = @$_GET['q'] ; 
     $trimmed = trim($var); //trim whitespace from the stored variable 
     $trimmed = mysql_real_escape_string($trimmed); 
    // rows to return 
    $limit=3; 

    // check for an empty string and display a message. 
    if ($trimmed == "") 
     { 
     echo "<p>Please enter a search...</p>"; 
     exit; 
     } 

    // check for a search parameter 
    if (!isset($var)) 
     { 
     echo "<p>We dont seem to have a search parameter!</p>"; 
     exit; 
     } 

    //connect to your database ** EDIT REQUIRED HERE ** 
    mysql_connect("localhost","root",""); //(host, username, password) 

    //specify database ** EDIT REQUIRED HERE ** 
    mysql_select_db("archivesys") or die("Unable to select database"); //select which database we're using 

    // Build SQL Query 
    $query = "select * from archdetaills_tbl where archivedate like \"%$trimmed%\" 
     order by archiveid"; // EDIT HERE and specify your table and field names for the SQL query 

    $numresults=mysql_query($query); 
    $numrows=mysql_num_rows($numresults); 

    // next determine if s has been passed to script, if not use 0 
     if (empty($s)) { 
     $s=0; 
     } 

    // get results 
     $query .= " limit $s,$limit"; 
     $result = mysql_query($query) or die("Couldn't execute query"); 

    // display what the person searched for 
    echo "<p>You searched for: &quot;" . $var . "&quot;</p>"; 

    // begin to show results set 
    echo "Results"; 
    $count = 1 + $s ; 

    // now you can display the results returned 
     while ($row= mysql_fetch_array($result)) { 
     $title = $row["archiveeemail"]; 

     echo "$count.)&nbsp;$title" ; 
     $count++ ; 
     } 

    $currPage = (($s/$limit) + 1); 

    //break before paging 
     echo "<br />"; 

     // next we need to do the links to other results 
    if ($s>=1) { // bypass PREV link if s is 0 
    $prevs=($s-$limit); 
    print "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?s=$prevs&q=$var\">&lt;&lt; 
    Prev 10</a>&nbsp&nbsp;"; 
    } 

// calculate number of pages needing links 
    $pages=intval($numrows/$limit); 

// $pages now contains int of pages needed unless there is a remainder from division 

    if ($numrows%$limit) { 
    // has remainder so add one page 
    $pages++; 
    } 

// check to see if last page 
    if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { 

    // not last page so give NEXT link 
    $news=$s+$limit; 

    echo "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?s=$news&q=$var\">Next 10 &gt;&gt;</a>"; 
    } 

$a = $s + ($limit) ; 
    if ($a > $numrows) { $a = $numrows ; } 
    $b = $s + 1 ; 
    echo "<p>Showing results $b to $a of $numrows</p>"; 

?> 


<!-- © http://www.designplace.org/ --> 

</body> 
</html> 

답변

0

$ _SERVER [ 'PHP_SELF는']은에 $_SERVER['PHP_SELF']에 올바른 방법

1

변화 $PHP_SELF입니다 :

  • $trimmed으로 이스케이프 처리해야합니다. 이 코드는 단축 할 수

    $trimmed = mysql_real_escape_string($trimmed); 
    $query = "select * from archdetaills_tbl where archivedate like \"%$trimmed%\" order by archiveid"; 
    
  • :

    $var = @$_GET['q'] ; 
    $trimmed = trim($var); 
    

    속으로 : 잠재적 인 SQL 주입입니다

    $trimmed = isset($_GET['q']) ? trim($_GET['q']) : ''; 
    
+0

더 나은 옵션이 MySQLi를 사용하는 것입니다 및 내장 된 매개 변수 보안을위한 바인딩. – DampeS8N

+0

고마워요 .... 둘 다 매우 도움이되었습니다. 그것을 확인하십시오. – Nas

+0

당신의 문제를 해결했다면 투표를 거쳐 선택된 대답으로 표시하는 것을 잊지 마십시오 – ariefbayu

관련 문제