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

  • SEARCH
  • Home
  • 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 6246027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:53+00:00 2026-05-24T12:36:53+00:00

I building a simple search feature that checks against a column desc in mysql

  • 0

I building a simple search feature that checks against a column “desc” in mysql table “products”

This is my code for the results, where $find is the user input string that has been formatted to uppercase.

 $dataQuery = 'SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'';
 $data = mysql_query($dataQuery) or die(mysql_error());

 //And we display the results 
 $pageContent = '';
 while($result = mysql_fetch_array( $data )) 
 { 
 $pageContent .= '
 <p>Desc:'.$result['desc'].' Price:'.$result['price1'].'</p>
 ';
 } 

Why am I getting the following error:

Warning: Division by zero in /path_to/test.php on line 29

Warning: Division by zero in /path_to/test.php on line 29
Query was empty

Line 29 is this line:

$dataQuery = 'SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'';

This query produces results in php myadmin, but when used in my script it gives the error.

Does anyone have any ideas on this?

EDIT:

Here is the full script with db connection info removed:

<?php

//This is only displayed if they have submitted the form 
if ($searching == 'yes') 
{ 
$pageContent .= '<h2>Results</h2>'; 

//If they did not enter a search term we give them an error 
if ($find == '') 
{ 
$pageContent .= '<p>You forgot to enter a search term</p>'; 
exit; 
} 

// Otherwise we connect to our Database 
$bccConn   = mysql_connect($bccHost, $bccUser, $bccPass) or exit(mysql_error());
             mysql_select_db($bccDB, $bccConn) or exit(mysql_error());

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
 $dataQuery = "SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'";
 $data = mysql_query($dataQuery) or die(mysql_error());

 //And we display the results 
 $pageContent = '';
 while($result = mysql_fetch_array( $data )) 
 { 
 $pageContent .= '
 <p>Desc:'.$result['desc'].' Price:'.$result['price1'].'</p>
 ';
 } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 {
$pageContent .= '
 <p>Sorry, but we can not find an entry to match your query</p>
 ';
 } 

 //And we remind them what they searched for 
$pageContent .= '
 <p><b>Searched For:</b>  '.$find.'</p>
 ';
 } 

ob_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/config.php';
require_once($docRoot . '/includes/layout.php');

$pageContent = '
<h2>orders</h2>
<form name="search" method="post" action="'.$PHP_SELF.'">
<p>Seach for: <input type="text" name="find" />
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" /></p>
</form>
';

echo $head1 . $pageDetails . $head2 . $header . $menu . $belowMenu . $content . $pageContent . $footer . $pageScripts;
exit;
?>
  • 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-24T12:36:54+00:00Added an answer on May 24, 2026 at 12:36 pm

    You are improperly nesting your quotes.

    Try:

    $dataQuery = "SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'";
    

    Single quotes will not expand your $find variable, and in fact the single quotes are terminated just after the LIKE leading PHP to evaluate % as the modulus operator.

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

Sidebar

Related Questions

I am building a simple website that needs 3 user levels (member, mod, admin)
I am building a simple Django app that will use scribd to display documents.
I'm building a simple site that allows users to post text content and I
I'm building a Narrow your results by feature similar to Best Buy's and NewEgg's
I'm building a large custom search for a wordpress site that is functioning as
I am building an app where I'd like to use a simple search to
I'm building a simple aggregator-type app that would pull in data from multiple websites
I am building my first PHP/MySQL site and i would like to return search
Hi I'm building a very simple search system using ASP.NET MVC. I had it
I'm building a simple recipe search engine with Ruby and Sinatra for an iPhone

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.