Page 1 of 1
[SOLVED] Problems with a form
Posted: Mon Mar 07, 2005 8:19 pm
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ї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?
Posted: Mon Mar 07, 2005 8:24 pm
by feyd
why do you use post when you want to pass the form data via get?
Posted: Mon Mar 07, 2005 8:28 pm
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?
Posted: Mon Mar 07, 2005 8:44 pm
by feyd
Allow the keywords to come in via post and get. Use get only if post is not available.

Posted: Mon Mar 07, 2005 8:56 pm
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їmember]' LIMIT 1");
while($row = mysql_fetch_array($user_id_query))
{
$user_id = $rowї'user_id'];
}
IF($_GETїmember] == ""){
$searchmember2 = "";
}ELSEIF($_GETїmember] != ""){
$searchmember2 = "AND $post_userid='$user_id'";
}
IF($_GETїsearchforum] == ""){
$searchforum2 = "";
}ELSEIF($_GETїsearchforum] != ""){
$searchforum2 = "AND $post_forum='$_GETїsearchforum]'";
}
IF($_GETїsearchin] == "message"){
$searchin2 = "post_text";
}ELSEIF($_GETїsearchin] == "subject"){
$searchin2 = "post_subject";
}
$search_thread = mysql_query("SELECT * FROM post WHERE $searchin2 LIKE '%$_GETїquery]%' $searchmember2 $searchforum2 ORDER BY post_date DESC");
while($row = mysql_fetch_array($search_thread)){
...
Posted: Mon Mar 07, 2005 9:00 pm
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.
Posted: Mon Mar 07, 2005 9:58 pm
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.