page.php?terms action

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

page.php?terms action

Post by m2babaey »

Hi
I'm trying to code a paid search. first i coded a test page that collects the search term and publisher id this way:

Code: Select all

<?php 
	require_once 'global.php';
$searchid="12";
$publisher="13";
$textlong ="80";
$label="websearch";
?>
<form method="GET" action="<?php echo "search.php?searchid=$searchid&publisher=$publisher"; ?>">
<input type="text" name="q" size="<?php echo $textlong; ?>">
<input type="submit" value="<?php echo $label; ?>">
</form>
and search.php is coded this way:

Code: Select all

<?php
	require_once 'global.php';
$searchid=clean($_GET['searchid']);
$publisher=clean($_GET['publisher']);
$q=clean($_GET['q']);

// then I search the database for $q and display the result
?>
as you see, i was trying to send the publisher details to search.php in order to increase their balance etc. but what i am getting in the result is not sending that info to search.php
Although when I view the source code of test.php ( in the browser ) it is:

Code: Select all

<form method="GET" action="search.php?searchid=12&publisher=13">
<input type="text" name="q" size="80">
<input type="submit" value="websearch">
</form>
But when I enter a keyword ( assume it hosting ) the action page is:
http://127.0.0.1/adcenter/search.php?q=hosting
plus sending notices:
Notice: Undefined index: searchid in g:\programs new\easyphp\www\adcenter\search.php on line 3
Notice: Undefined index: publisher in g:\programs new\easyphp\www\adcenter\search.php on line 4
why the action page (search.php) is missing the searchid and publisherid?
thanks
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

This is because your form method is set to get.

If your action is somepage.php?var1=value&var2=value and your method is set to get, then when the request is sent it will go to somepage.php but var1 and var2 will be removed and replaced with the values from your form.

Try changing the method to post.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are not checking to make sure the vars are set. Take a look at this code:

Code: Select all

<?php
$car = 'Honda';

echo $fishSticks;
?>
What is going to happen here?
Post Reply