2013-10-08 1 views
0

내가 페이지방법 헤더에 변수를 구문 분석() 페이지

`

<form method="post" action="" > 
        <div id="search"> 
         <form method="post" action="" > 
          <input type="text" name="keywords" placeholder = "Try your luck"/><input type="submit" value="Search" /> 
         </form> 

      <?php 

       if(isset($_POST['keywords'])){ 
        $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords']))); 
        $errors = array(); 

       if(empty($keywords)){ 
        $errors[] = 'Please enter a search term'; 
       } 
       else if(strlen($keywords)<3){ 
        $errors[] = 'Your search term must be three or more characters'; 
       } 
       else if(search_results($keywords) === false){ 
        $errors[] = 'Your search for '.$keywords.' returned no results'; 
       } 
       if(empty($errors)){ 
        header ('Location: search-page.php'); 
       } 
       else{ 
        foreach($errors as $error){ 
         echo $error; 
        } 
       } 
       } 

      ?> 

문제에이 코드를 가지고하는 것은 내가 searchpage.php 페이지에서 변수 $ 키워드를 뭐지 할 것입니다 . 어떻게 그것을 성취 할 수 있습니까?

편집 : 검색 page.php의 코드는 다음과 같습니다

 <?php include_once('headersearch.php'); 
include ('includes/func.inc.php'); 
global $variable; 
    ?> 


     <table id="content-area"> 

      <tr> 
       <td id="search-page" valign="top"> 


        <?php 

    $results = search_results($keywords); 
       $results_num = count($results); 
       if($results_num == 1){ 
        $s = "result"; 
       } 
       else{ 
        $s = "results"; 
       } 
       echo '<p>Your Search for <strong>',$keywords,'</strong> returned <strong>',$results_num,'</strong> ',$s,'</p>'; 
       foreach($results as $results){ 
        ?> 
        <table id="posts"> 
       <tr height="25px"><td><h1><?php echo $results['article_title'] ; ?></h1></td></tr> 
       <tr><td><h2><span>Posted on</span> :<?php echo date('l jS',$results['article_timestamp']) ?> <span>By</span>: BMC </h2></td></tr> 
       <tr><td><h3><?php echo substr($results['article_content'], 0, 300) ; ?>[...]</h3></td></tr> 
       <tr><td><a href="single.php?id=<?php echo $results['article_id']; ?>" title="TEST" class="button">Read Along</a></td></tr> 
       </table> 

        <?php 
       } 
       ?> 


        <?php include_once('sidebar.php'); ?> 

      </form> 

       </td> 
      </tr> 



<?php include_once('footer.php'); ?>  

최대한 빨리 psible

로 제발 도와주세요
+0

searchpage.php 페이지에서 $ keywords 변수를 사용한다는 것은 무엇을 의미합니까? searchpage.php 페이지에 대한 코드를 게시 할 수 있습니까? – Maximus2012

+1

다른 '

'안에있는 ''의 중첩이 잘못되어 예기치 않은 동작이 발생합니다. –

+0

또한 헤더 함수 호출 후에 exit를 추가해야합니다. – Maximus2012

답변

1
그냥 직접 search-page.php에 탐색 양식을 제출하는 경우 그것은 좋을 것

및 THAT 스크립트에 양식 유효성 검사 코드를 입력하십시오.

SQL 또는 HTML 컨텍스트에서 양식 데이터를 사용하고 있지 않으므로이 페이지에서 sql/html 이스케이프 처리를 수행 할 필요가 없습니다. 다음 기본 시스템을 사용해보십시오 :

$keywords = $_POST['keywords']; 

header('Location: search-page.php?keywords=' . urlencode($keywords)); 
+0

을 복사 한 다음 URL에서 키워드를 가져와야합니까? –

+0

@BogdanConstantin : 이제'search-page.php'에서'$ keywords = $ _GET [ 'keywords'];'할 수 있습니다. –

+0

'$ _GET [ 'keywords']'검색 페이지에서. 정확히 다른 PHP 스크립트에서 쿼리 변수를 얻을 같은. –

관련 문제