User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,423 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,365 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 600 | Replies: 9
Reply
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Redirect Output

  #1  
Apr 20th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 554
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 57
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Redirect Output

  #2  
Apr 20th, 2008
have the search form post to the new page you are talking about and process/display the results on that page.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Redirect Output

  #3  
Apr 20th, 2008
put the search key in a $_GET variable then perform the query in the header location page":

  1. $var=$_POST['searchtext'];
  2. header("Location: http://www.example.com?var=$var");
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: Redirect Output

  #4  
Apr 20th, 2008
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.

  1. while($result = mysql_fetch_array( $data ))
  2. {
  3. ?>
  4. <a href="http://www.someurl.com/<? $result['field'] ?>"> <? $result['field'] ?> </a>
  5. <br>
  6. <?
  7. }
  8. ?>

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!
Last edited by peter_budo : Apr 21st, 2008 at 3:45 am. Reason: Code tags edit, they are [code] not [php]
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 554
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 57
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Redirect Output

  #5  
Apr 21st, 2008
can you post the form? if so, then i can type some code up for you, so you can see how to do it.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Redirect Output

  #6  
Apr 21st, 2008
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:

  1. $var=$_GET['var'];
  2. //put your search query here...
  3. $query="Select * from table where field LIKE '%$var%'";
  4. $data=mysql_query($query);
  5. //put your display result here...
  6. while($result = mysql_fetch_array( $data ))
  7. {
  8. ?>
  9. <a href="http://www.someurl.com/<? $result['field'] ?>"> <? $result['field'] ?> </a>
  10. <br>
  11. <?
  12. }
  13. ?>
  14.  
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: Redirect Output

  #7  
Apr 21st, 2008
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.
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Redirect Output

  #8  
Apr 21st, 2008
try to run the query in Mysql,maybe your query is incorrect.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Redirect Output

  #9  
Apr 22nd, 2008
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" ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: Redirect Output

  #10  
Apr 22nd, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC