Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4110878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:59:32+00:00 2026-05-20T21:59:32+00:00

I am trying to add a search function to my website. Right now it’s

  • 0

I am trying to add a search function to my website. Right now it’s very rudimentary, and the search is simply pulling results from MySQL using select. The problem is, the search works great when I test it on localhost but doesn’t work at all when I put it on the server. When it is used it simply selects the entire database. I believe the problem is that the variable isn’t getting passed to the search results page, but I don’t know.

Here’s the code for the search box. It is in a referenced file called “header.php”:

<html>
<head>

<body>
<div class="title"><img style="width:100%;" src="title.gif" /></div>
<div class="search">Search: 
<form style="display:inline" name="search" action="search.php" method="get"><?php echo"         <input type='text' name='query' />";?>
<a href="javascript: searchSubmit()"><img src="seo.png" alt="Search" title="Search" />   </a></form></div>
<ul class="menu">
<li><a href="index.php#home">home</a></li>
<li><a href="submit.php?title=&desc=">post an idea</a></li>
<li><a href="#about">about us</a></li>
<li><a href="#contact">contact us</a></li>
<li><a href="login.php">log in</a></li>
</ul>

</body>
</html>

And here’s the code from search.php:

<?php
$search=$_GET['query'];
$search=mysql_real_escape_string($search);
?>
<html>
<head>
<?php
echo "<title>Search: $search</title>";
?>
<link rel="stylesheet" type="text/css" href="mainstyle.css" />
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<div class="title"><img style="width:100%;" src="title.gif" /></div>
<div class="search">Search: 
<form style="display:inline" name="search" action="search.php" method="get"><?php echo"    <input type='text' name='query' value='$search'/>";?>
<a href="javascript: searchSubmit()"><img src="seo.png" alt="Search" title="Search" /></a></form></div>
<ul class="menu">
<li><a href="index.php#home">home</a></li>
<li><a href="submit.php?title=&desc=">post an idea</a></li>
<li><a href="#about">about us</a></li>
<li><a href="#contact">contact us</a></li>
<li><a href="login.php">log in</a></li>
</ul>
<?php

mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("date_ideas") or die(mysql_error());

$result=mysql_query("SELECT * FROM ideas WHERE title LIKE '%".$search."%' ORDER BY    post_date DESC");
echo "SELECT * FROM ideas WHERE title LIKE '%".$search."%' ORDER BY post_date DESC";

echo "<span id='none'>";
while($row = mysql_fetch_array($result))
{
$id=$row['id'];
echo "<h2 class='center'><a href='ideaview.php?id=$id' title='View ".$row['title']."     Description'>" . $row['title'] . "</a><br/>";
echo "<span class='date'>";
$date=$row['post_date'];
$time=time();

if (($time-$date)<120)
{
echo "Posted 1 minute ago";
}

else if (($time-$date)>120&&($time-$date)<3600)
{
$minutes=($time-$date)/60;
echo ("Posted " . round($minutes) . " minutes ago");
}
else if (($time-$date)>3600&&($time-$date)<7200)
{
echo "Posted 1 hour ago";
}
else if (($time-$date)<86400&&($time-$date)>7200)
{
$hours=($time-$date)/3600;
echo ("Posted " . round($hours) . " hours ago");
}
else if (($time-$date)<172800&&($time-$date)>86400)
{
echo "Posted 1 day ago";
}
else
{
echo ("Posted on " . date("m-d-y",$date));
}
echo "</span></h2>";
}
echo "</span>";
?>

<script type="text/javascript">
document.getElementById("none");
if (none.innerHTML == "")
{
none.innerHTML="<p class='center'>There are no ideas matching your search</p>";
}
</script>
</body>
</html>

Lastly, here’s the code for the javascript used to submit the form:

var valid=true;

function validate(field, helptext, type, min, max, field1)
{
var x=field.value;
var text=document.getElementById(helptext);
if (x==null || x=="")
{
if (text!=null)
    {
    text.innerHTML="Please input "+field.id;
    }
valid=false;
}
else if (type=="length")
{
valLength(min,max,field,helptext);
}
else if (type=="email")
{
valEmail(field,helptext);
}
else if (type=="pass")
{
valPass(field, field1, helptext);
}
else
{
if (text!=null)
    {
    text.innerHTML="";
    }
valid=true;
}
}

function searchSubmit()
{
validate(search.query);
if (valid==true)
{
search.submit();
}
else
{
alert("Please enter a search term");
}
}

As I said, when I use it on my localhost on my computer, it works perfectly, returning only the rows where title matches the search. When I put it on the server, however, it returns all the rows in the table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:59:33+00:00Added an answer on May 20, 2026 at 9:59 pm

    I can’t see anything in the code given that would cause this. I think your analysis is correct; I’d imagine $_GET['query'] is empty for some reason.

    You could make your code a little more robust by doing an explicit check for this: you want that to be an error case, not “return everything” case. But besides confirming your theory, this won’t solve the problem outright.

    The only thing I can think of is to make sure that $_GET exists on your server; it was introduced in PHP 4.1.0, which is now a very long time ago. Still, it’s possible that the PHP on your remote server is ancient.

    Good luck!


    Update

    You’re using mysql_real_escape_string, which requires a connection, before you make the connection. If there isn’t one, one is attempted using default parameters which is working on your local machine, but not on your [presumably more secure] production server.

    This is causing the escaping to fail, and FALSE to be written into $query.

    Just use mysql_escape_string which doesn’t require a connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add pagination to my wordpress search results. I was able to
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I was trying to add a favicon to a website earlier and looked for
we are trying to add searching to our web site and want this search
I am looking at trying to expand my search function for my small project.
As you can read from the title, I'm trying to add class=current part to
I'm trying add a tab to my web page that looks like this: Using
Trying to add an onclick handler to my tabs, and can't seem to get
I'm trying to add support for stackoverflow feeds in my rss reader but SelectNodes
I am trying to add a project reference or swc to papervision in FlashDevelop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.