dqsot35145 2013-10-08 15:37
浏览 108
已采纳

如何将变量解析为header()页面

I have this code on a page

`

    <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;
                    }
                }
                }

            ?>

The problem is that I want to youse the variable $keywords on the searchpage.php page. How can I acomplish that?

EDIT: The code for search-page.php is :

        <?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' ); ?>      

Please help me as fast as psible

  • 写回答

1条回答 默认 最新

  • douyanyan1123 2013-10-08 15:41
    关注

    It'd be better if you just submitted the search form to search-page.php directly and put the form validation code into THAT script.

    That being said, you don't need to do sql/html escaping on this page, because you're not using the form data in either an sql OR html context. Try this basic system:

    $keywords = $_POST['keywords'];
    
    header('Location: search-page.php?keywords=' . urlencode($keywords));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?