Jump to content

[SOLVED] search form - fill at least ONE field


sirtemplar

Recommended Posts

i have a search form for book AUTHOR and TITLE from my database. Before, when user clicks the form without any input on AUTHOR or TITLE on the form, the script prints all data from database. now with the script below, user should input on AUTHOR and TITLE fields to get a result or else they get an error. BUT what i want is that AT LEAST they input on AUTHOR OR TITLE field, not both required. THANKS.

 

{$Author = $_POST['Author'];}  
{$Title = $_POST['Title'];}  

if($_POST['Author'] == "" || $_POST['Title'] == "")
{
print "An error has occured. Author and Title require input";
  
} 

else 
{
$result = mysql_query ("SELECT * FROM catalogue
                       WHERE Author LIKE '%$Author%'
                       AND Title LIKE '%$Title%'
                       ORDER BY Title ASC, Author
                      ",$conn);  

$totalrows = mysql_num_rows($result);

if ($row = mysql_fetch_array($result)) {  

do { 

 

now it's not printing ALL anymore when there is no user input on the search form BUT now to search user must input on both fields! what i want is that AT LEAST they input on TITLE or AUTHOR field. Thanks for any help

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.