开发者

redirect page after completing update or insertion

开发者 https://www.devze.com 2023-02-11 07:02 出处:网络
There are two pages called result.php and getdata.php the result.php will show a search r开发者_JAVA百科esults. if search term is not in database then it should redirect to getdata.php .

There are two pages called result.php and getdata.php

the result.php will show a search r开发者_JAVA百科esults. if search term is not in database then it should redirect to getdata.php .

getdata.php will analyze query and grab data from other resources then insert / update MySQL database. immeadiate after inserting/updating database then it should redirect to result.php

Finally result.php will show result as per the query term.

how can be this done with php and mysql??


header('location: url');

This should help you, just put instead of url something like results.php.

Any issues with redirecting let me know, it could be due to output_buffering being turned off.


Check out the PHP docs for mysql_num_rows and header. Below is almost straight from the docs...

<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

if ( $num_rows > 0 ){
    // do something with your SQL result here
} else {
    // redirect to result.php if no rows were found.
    header('location: result.php');
}

?>


actually, I'd put all the code in one php-page, then you wouldn't have to redirect, and easier to maintain.

//if no record from search, do the insert now...
code...
//end insert

regards,

//t

0

精彩评论

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

关注公众号