[SOLVED] Problems with a form

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
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

[SOLVED] Problems with a form

Post by Wldrumstcs »

I have a form for a DB search on my site. One of the inputs is called 'keyword'. Under the form action, I have:

Code: Select all

<form method='POST' action='search.php?query=<? echo "$_POST&#1111;keyword]"; ?>'>
However, I have to click on the submit button twice for this to work. The first time you click it, the query variable in the URL remains empty. How should I change this?
Last edited by Wldrumstcs on Mon Mar 07, 2005 9:59 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why do you use post when you want to pass the form data via get?
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

Now that I have realized my stupidity, how would I keep some of the variables in the form from showing up in the URL if I use GET?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Allow the keywords to come in via post and get. Use get only if post is not available. :?:
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

Next question:

What is wrong with my setting of the $searchmember2 and $searchforum2 variables? If they are empty, it works okay, but not otherwise.

Code: Select all

$user_id_query = mysql_query("SELECT user_id FROM users WHERE username='$_GET&#1111;member]' LIMIT 1");         
		while($row = mysql_fetch_array($user_id_query)) 
      &#123; 
        $user_id = $row&#1111;'user_id']; 
&#125;

IF($_GET&#1111;member] == "")&#123;
$searchmember2 = "";
&#125;ELSEIF($_GET&#1111;member] != "")&#123;
$searchmember2 = "AND $post_userid='$user_id'";
&#125;
IF($_GET&#1111;searchforum] == "")&#123;
$searchforum2 = "";
&#125;ELSEIF($_GET&#1111;searchforum] != "")&#123;
$searchforum2 = "AND $post_forum='$_GET&#1111;searchforum]'";
&#125;
IF($_GET&#1111;searchin] == "message")&#123;
$searchin2 = "post_text";
&#125;ELSEIF($_GET&#1111;searchin] == "subject")&#123;
$searchin2 = "post_subject";
&#125;

$search_thread = mysql_query("SELECT * FROM post WHERE $searchin2 LIKE '%$_GET&#1111;query]%' $searchmember2 $searchforum2 ORDER BY post_date DESC"); 
   while($row = mysql_fetch_array($search_thread))&#123;
...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo out the query.. I'd bet some data isn't there.. like $post_forum for instance. Remember to quote your named array indices.
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

I found the problems: $post_forum and $post_userid should not have the $ in front of them as they are simply columns in a DB.
Post Reply