Hey guys, I am just learning php and mysql for the first time and I would really appreciate your help. I have created a search engine for my website which searches through a database and then returns the correct results. All of that is working great, EXCEPT for the fact that I want the results to be printed on a new page. I know how to redirect to a new page by uing header(Location: url), BUT when I redirect to the new page, it will not print out the results on the new page. Instead it is printing an error (Warning: mysql_fetch_array(): supplied argument is not a valid MySQL), which tells me that it is not reading any of the variables from the previous page. Can anyone give me any advice for how to perform a search on one page, and then redirec the output to a new page?? Thanks a lot guys.

have the search form post to the new page you are talking about and process/display the results on that page.

Hey guys, still having problems. I appreciate the responses though. I would post my code but that would actually make it more confusing for you. But here is where the problem is coming from....Here I am saying if there is a match then print out the results.

while($result = mysql_fetch_array( $data )) 
{ 
?>
<a href="http://www.someurl.com/<? $result['field'] ?>"> <? $result['field'] ?> </a> 
<br>
<?
} 
?>

I am not sure if this helps you guys at all, but this is what is printing the results right now on the same page that I have the search form. I just want these results printed on the page I am redirecting to. I apologize but you must realize I just started learning php and mysql two days ago so I basically need exact instructions. Thanks for your help!

can you post the form? if so, then i can type some code up for you, so you can see how to do it.

like what I have said before,put the search key( the one that is inputted by the user in the textbox in a variable then perform the search query in the page you are redirecting to.

for example this is the page where you will redirect:

$var=$_GET['var'];
//put your search query here...
$query="Select * from table where field LIKE '%$var%'";
$data=mysql_query($query);
//put your display result here...
while($result = mysql_fetch_array( $data ))
{
?>
<a href="http://www.someurl.com/<? $result['field'] ?>"> <? $result['field'] ?> </a>
<br>
<?
}
?>

I used the code like you showed me above and I keep getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

I am not sure why it is, but I know the variable is being transferred.

try to run the query in Mysql,maybe your query is incorrect.

Why do you want to redirect after querying the table ? Why not query the table after "implicitly redirecting" to another page using form method="post" ?

That is a good question. My answer: I just started learning php a couple of days ago : ) So in other words, I don't even know what you're talking about. I did get it to work though so thanks for the help guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.