开发者

redirect to another page and direct back to main?

I do have a search engine which is written in php with MySQL

when user search something the result will be shown on search.php page. if the search term is not stored in database then user should be diverted to an another page cal开发者_如何学Cled getdata.php show a message saying we are grabbing your data at the same time it will grab data then store it into database then again redirect back user to search.php and show the result.

I have familiar up to this

search.php

    $data = $_GET['q']
    //databse connection
    //empty check
    //mysql query
    $row = mysql_fetch_assoc($result);
    if($row > 0){

    //read $row
    //show result

}else{ //here what should I give `header` command wont work smoe times as it gives error like `header information is already send`. I heard that `header` command should be given on top of every php page

getdata.php

here I am not sure how to show progress message then insert data in database then redirect to search.php


The header function needs placing before any content is output - not necessarily at the top of the page. Ensure you have no content before your opening php tag on your script pages.


header information is already send means you have output before the header('location:xyz'). You can prevent it by collecting output in a variable and echo it at the end. Other way it using ob_start / ob_flush pair. http://php.net/manual/en/function.ob-start.php it buffer the output too.

Sometimes there is raw output before any php code because of you start your php file with an empty line befoe

Rare but if you file is UTF8 but it has BOM it can be a problem too (as BOM can be printed, if sites char coding isn't UTF8)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜