Skip to main content
October 25, 2006
Question

PHP Search function

  • October 25, 2006
  • 4 replies
  • 587 views
I have been running into a block and I can't seem to get my search function to work. I have created a form seen below.

<form action="index.php" method="get" name="searchFrm" id="searchFrm">
<input name="search" type="text" id="search" value="<?php echo $_GET['search']; ?>">
<input type="submit" value="Search Users">
</form>

As well I changed the SQL code but some how it is not working for me. These are the various methods I used and still no results.

$query_rsUsers = "SELECT adminusers.userID, adminusers.userName, adminusers.firstName, adminusers.lastName, adminusers.`date`, adminusertypes.userType
FROM adminusers, adminusertypes
WHERE adminusers.userTypeID = adminusertypes.userTypeID
AND (userName LIKE '%$_GET['search']%') <!-- Changed Code-->
";

OR

$query_rsUsers = "SELECT adminusers.userID, adminusers.userName, adminusers.firstName, adminusers.lastName, adminusers.`date`, adminusertypes.userType
FROM adminusers, adminusertypes
WHERE adminusers.userTypeID = adminusertypes.userTypeID
AND (userName LIKE '%URL.search%') <!-- Changed Code-->
";

I am out of options. Thank you for all those who help.


Thank you,
AdonaiEchad

PS. Dreamweaver MX 2004 has generated most of the code you see attached.

This topic has been closed for replies.

4 replies

November 4, 2006
hi,
firstly I would get rid of any $HTTP_GET_VARS and change it to $_GET unless you are using php 4.0 or less, you can check php.net manual on the correct naming according to your type of php. Just make sure your host is using the same php as you as well.
$colname_Search = "1";
if (isset($HTTP_GET_VARS['SearchUsers'])) {
$colname_Search = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['SearchUsers']
: addslashes($HTTP_GET_VARS['SearchUsers']);
}

Also if you used the advanced recordset I would try:
Search = $_GET['SearchUsers']
using the = as the default value instead of 1
I found that using 1 didn't work either. Try different variables and see if something works better than what you had. There is a tutorial on recordsets and variables used and how to prevent problems on dmxzone:
http://www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=7072

When I was doing my advanced search e.g. using three dropdown menus to find a defined result, I couldn't get it working because I hadn't made a form variable for the form to make it work.
If you don't know how to do this, it is simple and I use it all the time now.
You have a name for your textfield, textarea etc. for your form. This is the name you want to use for the variable. It has to match or it doesn't work.
You go to the bindings panel and click on the plus sign. You will see a url, form, session, cookie, server etc. variables available.
Take a peek at this page if you haven't already.
http://www.adobe.com/devnet/dreamweaver/articles/php_blog3_06.html

Hope that helps
October 26, 2006
Hi I have this link for you that helped me immensely when doing my search pages.
Hope it helps you too.
http://www.adobe.com/devnet/dreamweaver/articles/recordstore_part2_php.html
October 27, 2006
I tried to do the method of that was posted by jjjhbj111. I was working on the search function at this link that Adobe has, Search feature. It worked when I did the tutorial, however, when I am trying my own work it seems not to work.

mysql_select_db($database_conLOMMI, $conLOMMI);

$Search = mysql_query($query_Search,
$conLOMMI) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$totalRows_Search = mysql_num_rows($Search);

Dreamweaver makes an automatic connection to the database in a folder called Connections and in there is the php connections file.
conLOMMI.php


What Dreamweaver has paced in the conLOMMI.php is the following...

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conLOMMI = "localhost";
$database_conLOMMI = "lommidata";
$username_conLOMMI = "root";
$password_conLOMMI = "";
$conLOMMI = mysql_pconnect($hostname_conLOMMI, $username_conLOMMI, $password_conLOMMI) or trigger_error(mysql_error(),E_USER_ERROR);
?>

Now I really do not know what to do from here. I am out of options. Your help is greatly appreciated.

Thank you,
AdonaiEchad

Inspiring
October 26, 2006
Depending on the functionality you need, Tom Muck's search extension is excellent.

Tom Muck's dynamic search extension

Iain
Inspiring
October 25, 2006
AdonaiEchad wrote:
> As well I changed the SQL code but some how it is not working for me. These
> are the various methods I used and still no results.
>
> AND (userName LIKE '%$_GET['search']%') <!-- Changed Code-->
> ";

You need to remove the single quotes in $_GET['search'] for two reasons.
Firstly, they conflict with the single quotes surrounding the whole
search string. More importantly, associative arrays must be treated
differently in a double-quoted string. This last feature is a PHP quirk
that catches a lot of people out. Change the above section of code like
this:

AND (userName LIKE '%$_GET[search]%')";

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
October 26, 2006
It still did not work.

I tried to do a different method and still not functional.

I used dreamweaver 2004 MX and made a record set called. "rsUsers" in the advance mode, this is what I have as my sql statement.
SELECT adminusers.userID, adminusers.userName, adminusers.firstName, adminusers.lastName, adminusers.`date`, adminusertypes.userType
FROM adminusers, adminusertypes
WHERE adminusers.userTypeID = adminusertypes.userTypeID
ORDER BY lastName ASC

How do I make the search functional, I tried ever way possible and no luck.

My search text area is the following...
form action="index.php" method="get" name="searchFrm" id="searchFrm">
<input name="SearchString" type="text" id="SearchString" value="<?php echo $_GET['SearchString']; ?>" size="20">
<input type="submit" value="Search User">
</form>

I'm lost don't know what to do.

Thank you,
AdonaiEchad