form textbox with search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greets,
The following code snippet receives data from a textbox named searchtext if
the user types in a word.

It then tries to match that word from the mysql database using:

$searchtext = $_POST['searchtext'];
if ($searchtext != '') { // Some search text was specified
  $where .= " AND blurb LIKE '%$searchtext%'";
}

and adding on to the WHERE sql statement.

If the user clicks the submit _without_ inserting a word, the whole database
is output due to the basic select sql statement of:

$select = 'SELECT DISTINCT merch.ID, merch.blurb, merch.price';
$from   = ' FROM merch';
$where  = ' WHERE 1=1  ';

I am trying to work out a way to display a page that might say - "Please
enter a word" if the user fails to insert a word in the textbox.

Any help greatly appreciated.
TR
.................


<?php
$dbcnx = mysql_connect('localhost', 'root', 'mypass');
mysql_select_db('sitename');

// The basic SELECT statement
$select = 'SELECT DISTINCT merch.ID, merch.blurb, merch.price';
$from   = ' FROM merch';
$where  = ' WHERE 1=1  ';

$lid = $_REQUEST['lid'];
if ($lid != '') { // An lot is selected
  $where .= " AND lid='$lid'";
}

$searchtext = $_POST['searchtext'];
if ($searchtext != '') { // Some search text was specified
  $where .= " AND blurb LIKE '%$searchtext%'";
}
?>

<table border="1" align="center">
<tr><th>Click for
details</th><th>Description</th><th>Price</th><th>Edit</th><th>Delete</th><t
h>Photo</th></tr>

//etc.............

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux