I'm doing a search application for my project. My code can prompt
alert popup window when the user doesn't key in any keywords. However,
if the user keys in any keywords, it juz return "Please enter
keywords!" whatever it is. I had set proper looping for suitable
condition checking, but it is still generate the same problem.
<html>
<head>
<title>Searchin g Results</title>
</head>
<body background="abs tract.gif">
<link rel="STYLESHEET " type="text/css" href="styleshee t.css">
<?php
echo "<h1>Search ing Results</h1>";
//perform search
if($_POST['submit'] == "")
{
echo "post";
//if(isset($_POST['submit']))
//{
$db = mysql_connect(" localhost", "root", "") or die(mysql_error ());
mysql_select_db ("bulletin", $db) or die(mysql_error ());
$searchWords = explode(" ", $_POST['textfield']);
foreach ($searchWords as $word)
{
if ($word)
{
$whereParts[] = "`TITLE` LIKE '%{$word}%' OR `DEPARTMENT` LIKE '%
{$word}%'" ;
}
}
$whereClause = implode(" OR ", $whereParts);
$query = "SELECT * FROM `bul_data` WHERE {$whereClause} ORDER by
`DATE`";
$res = mysql_query($qu ery) or die(mysql_error ());
echo "query=".$query ;
if(mysql_num_ro ws($res)>0)
{
echo "<table width=\"100%\" border=\"1\">";
echo "<tr>";
echo "<th class=\"normal\ ">Date</th>";
echo "<th class=\"normal\ ">Title</th>";
echo "<th class=\"normal\ ">Departmen t</th>";
echo "<th class=\"normal\ ">Link</th>";
echo "</tr>";
while($row=mysq l_fetch_assoc($ res))
{
$date = $row['DATE'];
$date = decode($date);
$title = $row['TITLE'];
$title = decode($title);
$department = $row['DEPARTMENT'];
$department = decode($departm ent);
$link = $row['LINK'];
$link = decode($link);
echo "<tr>";
echo "<td><strong>$d ate</strong></td>";
echo "<td><strong>$t itle</strong></td>";
echo "<td>$departmen t</td>";
echo "<td><a href = \"$link\">$link </a></td>";
echo "</tr>";
}
echo "</table>";
}
//}
}
else
{
echo "38292930";
echo "Please enter keywords!";
//echo "<script language=\"Java Script\">
//<!--
//alert('Please enter keywords!');
//-->
//</script>";
}
//function decode($string)
//{
// $string = str_replace("&a mp;", "&", $string);
// $string = str_replace("&l t;", "<", $string);
// $string = str_replace("&g t;", ">", $string);
// $string = str_replace("'" , "'", $string);
// $string = str_replace("&q uot;", "\", $string);
//
// return $string;
//}
function decode($text)
{
$text = html_entity_dec ode($text,ENT_Q UOTES);
return $text;
}
?>
<br>
<table width ="100%" border ="0" cellspacing ="1" cellpadding ="2">
<tr>
<td class="normal" width ="10%" align ="center"><a href =
"homepg.php">Ho me | </a><a href =
"search.php">Se arch Again?</a></td>
</tr>
</table>
</body>
</html> 2 1778
caine wrote:
I'm doing a search application for my project. My code can prompt
alert popup window when the user doesn't key in any keywords. However,
if the user keys in any keywords, it juz return "Please enter
keywords!" whatever it is. I had set proper looping for suitable
condition checking, but it is still generate the same problem.
Sorry to say Caine, but your code is a mess.
You just don't throw code like that to a group and expect us to unweave it.
Bad nettiquette.
A friendly word of advise: You might consider to clean it up before posting
here in future....
We REALLY don't care about the stylesheet, the databasequeries (in this
case), your HTML-markup, string decoding, etc.
It is just noise.
You even commented out if-statements, making the spaghetti even worse (for
you and for us) to unravel.
I made a few comments though:
>
<html>
<head>
<title>Searchin g Results</title>
</head>
<body background="abs tract.gif">
<link rel="STYLESHEET " type="text/css" href="styleshee t.css">
<?php
echo "<h1>Search ing Results</h1>";
//perform search
if($_POST['submit'] == "")
What is this excactly doing in your opinion?
You are checking if the POST contains a name/value pair that goes by the
name 'submit' and contains an empty string.
Is that what you WANT to check?
I expect you want to check IF the form has been posted.
Try something that actually tests that, like:
[assuming your submitbutton exists in your form]
if (isset($_POST["submit"])){
// form received
} else {
// no form received
}
{
echo "post";
So this part of the script will only be reached if you posted a form with
method POST, containing a 'submit' that is an empty string.
>
//if(isset($_POST['submit']))
//{
$db = mysql_connect(" localhost", "root", "") or die(mysql_error ());
mysql_select_db ("bulletin", $db) or die(mysql_error ());
$searchWords = explode(" ", $_POST['textfield']);
foreach ($searchWords as $word)
{
if ($word)
{
$whereParts[] = "`TITLE` LIKE '%{$word}%' OR `DEPARTMENT` LIKE '%
{$word}%'" ;
}
}
$whereClause = implode(" OR ", $whereParts);
$query = "SELECT * FROM `bul_data` WHERE {$whereClause} ORDER by
`DATE`";
$res = mysql_query($qu ery) or die(mysql_error ());
echo "query=".$query ;
if(mysql_num_ro ws($res)>0)
{
echo "<table width=\"100%\" border=\"1\">";
echo "<tr>";
echo "<th class=\"normal\ ">Date</th>";
echo "<th class=\"normal\ ">Title</th>";
echo "<th class=\"normal\ ">Departmen t</th>";
echo "<th class=\"normal\ ">Link</th>";
echo "</tr>";
while($row=mysq l_fetch_assoc($ res))
{
$date = $row['DATE'];
$date = decode($date);
$title = $row['TITLE'];
$title = decode($title);
$department = $row['DEPARTMENT'];
$department = decode($departm ent);
$link = $row['LINK'];
$link = decode($link);
echo "<tr>";
echo "<td><strong>$d ate</strong></td>";
echo "<td><strong>$t itle</strong></td>";
echo "<td>$departmen t</td>";
echo "<td><a href = \"$link\">$link </a></td>";
echo "</tr>";
}
echo "</table>";
}
//}
}
else
{
And here we are when the form did not contain a 'submit' with value empty
string.
echo "38292930";
echo "Please enter keywords!";
//echo "<script language=\"Java Script\">
//<!--
//alert('Please enter keywords!');
//-->
//</script>";
}
End of if-statement.
<snipped the rest of the script>
Since we can only guess what is actually in your form, I cannot say with
certainty this is the problem, but it sounds likely.
Also, if you are in doubt WHAT is excactly pased to PHP by some form, just
do this:
echo "<pre>";
print_r($_POST) ;
echo "<pre>";
Regards,
Erwin Moller
caine wrote:
I'm doing a search application for my project. My code can prompt
alert popup window when the user doesn't key in any keywords. However,
if the user keys in any keywords, it juz return "Please enter
keywords!" whatever it is. I had set proper looping for suitable
condition checking, but it is still generate the same problem.
After real quick look, it seems that first condition
if($_POST['submit'] == "")
fails and that's why it goes to
Please enter keywords -part.
Is the method of your previous form post or get?
Is the name of the submit button "submit" for sure? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Adrian Parker |
last post by:
I have a database of 200+ tables (two tables per school), each with 100 -
4000 records (one record per student). A contract I'm looking at wants to
be able to do a search across all the tables, searching for values a user
inputs via a Search form.
I have a solution, but I don't think it'll work on large scales.
Is there a better bet then querying table 1, finding matching values and
writing those records into an ADO variable, closing...
|
by: RiceGuy |
last post by:
Hi! I'm looking for ideas on what would the best approach to design a
search system for a RSS feeds. I will have some 50 RSS feeds (all RSS
2.0 compliant) stored locally on the web server. Now I'm wondering
what would the best method to allow searching of these RSS files.
Since the search will cater to multiple users the search system has to
be robust and efficient. Some ideas that I have for the RSS search
system are:
1. Store all RSS...
|
by: Zambo via SQLMonster.com |
last post by:
Hi!
We have Sql Server 2000 in our server (NT 4). Our database have now about
+350.000 rows with information of images. Table have lot of columns
including information about image name, keywords, location, price, color
mode etc. So our database don?t include the images itself, just a path to
the location of every image. Keywords -field have data for example like
this:
cat,animal,pet,home,child with pet,child. Now our search use Full-Text...
|
by: Noticedtrends |
last post by:
Can inference search-engines narrow-down the number of often irrelevant
results, by using specific keywords; for the purpose of discerning
emerging social & business trends?
For example, if authors of content subconsciously mention the keywords
"lately and noticed" within the same brief sentence, the reader may
infer "an unintended message" through the process of "inferential
scanning;" a method of noting "semantic anomalies" which may...
|
by: D. Dante Lorenso |
last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org
is extremely SLOW. Considering this is a website for a database
and databases are supposed to be good for indexing content, I'd
expect a much faster performance.
I submitted my search over two minutes ago. I just finished this
email to the list. The results have still not come back. I only
searched for:
SECURITY INVOKER
| |
by: SC |
last post by:
I'm developing a site that may eventually have a very large database of
users (hopefully, but who knows). It will be a community website where
users can search each other (think Friendster, Classmates, every dating site
out there, etc.).
Often there will be queries with multiple joins and sometimes may include a
few fulltext searches. Each page of results will have a limited number of
results displayed (obviously). As I understand it,...
|
by: Sullivan WxPyQtKinter |
last post by:
I am now using XML to record my lab records in quite a complex way, in
which about 80 tags are used to identify different types of data. I
think it is a good idea to search for a popular and mature XML search
engine before I started to program it myself:
I need the following functions:
Search and get all the records that share the same tree structures.
Search records containing a specific node or sub tree structres.
Does anyone know...
|
by: justobservant |
last post by:
When more than one keyword is typed into a search-query, most of the
search-results displayed indicate specified keywords scattered
throughout an entire website of content i.e., this is shown as three
bolded periods '...' in search-result listings.
Additionally, most content is outdated; as many users need up-to-date
content. Hence, filtering-through search-results becomes quite
cumbersome.
The newsgroup listings allow detailed...
|
by: ARC |
last post by:
I wrote a quick routine to search for the text "Mainmenu" in the MSysQueries
table, in the expression field.
I was able to find and alter all occurences of this phrase with the
exception of 3:
Mainmenu found in object ~sq_cfSellOld~sq_ccboContact, ObjectID: -2147483106
Mainmenu found in object ~sq_cfServiceOld~sq_ccboContact,
ObjectID: -2147483074
Mainmenu found in object ~sq_cfServiceOld~sq_clstJobs, ObjectID: -2147483069
|
by: prn |
last post by:
Hi folks,
I have an inherited access application. At least a half-dozen people have worked on this one before me. The application contains hundreds of queries.
My (current) problem involves some information that is encoded in, shall we say, a non-intuitive way. And that encoding has changed over the years. One of my users noticed today that a report she ran produced an unexpected result. Tracking it down, I found that different queries...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |