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 234251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:10:11+00:00 2026-05-11T20:10:11+00:00

Ive been programming a search form with three fields, and the one that is

  • 0

Ive been programming a search form with three fields, and the one that is giving me trouble is the one that use the “LIKE” clause in sql.

Here is the code:

            <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
             <p>

             <label for="nome">Nome Empresa:</label>
             <input type="text" name="nome"  id="nome"/>

             <label for="concelho">Concelho:</label>
                <select name="concelho">
                        <option id="" selected="selected" value="">Seleccione o Concelho</option>
                          <option value="1" id="1">Um</option>
                          <option value="2" id="1">Dois</option> 
                 </select>

             <label for="actividade">Actividade:</label>
                <select name="actividade">
                        <option id="" selected="selected" value="">Seleccione a actividade</option>
                          <option value="1" id="1">Actividade Um</option>
                          <option value="2" id="1">Actividade Dois</option>    
                 </select>   
             </p>
             <p>
             <input type="submit" name="pesquisar" value="Pesquisar"/>
             </p>
            </form>

// the sql (not all)

                    $nome = mysql_real_escape_string($_POST['nome']);



                // Pesquisa a partir da form
                if (isset($_POST['pesquisar'])) {

                $queryStr = 'SELECT * FROM ';
                if(!empty($nome)){
                    $queryStr .= 'tbl_clientes  WHERE nome LIKE '%'$nome'%'';
                }

Why does it give me this error twice?

Warning: Division by zero in .. on line ..

Warning: Division by zero in .. on line ..

I’m not making a Division…am i?

Thanks in advance

  • 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-11T20:10:11+00:00Added an answer on May 11, 2026 at 8:10 pm

    Yes, you do. The % signs used by LIKE are outside the string, and hence interpreted as the modulo operator. Remove the additional ‘ signs.

    $queryStr .= "tbl_clientes WHERE nome LIKE '%$nome%'";
    

    (Here I used a mixture of single and double quotes to sove the problem. Eoin Campbell’s solution of escaping the inner single quotes is just as valid. You will often find that you will need to use (a combination of) these techniques when programming in PHP.)

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

Sidebar

Related Questions

I've been programming for 10+ years now for the same employer and only source
I've been programming in C# and Java recently and I am curious where the
I've been programming in C,C++,C# and a few other languages for many years, mainly
i've been programming a while in D (http://www.digitalmars.com/d/) now. I prefer it to Java
I've been programming in Ruby for a few months now, and I'm wondering when
I've been programming in C-derived languages for a couple of decades now. Somewhere along
I've been programming in Java for a while and just got thrown onto a
I've been programming opengl using glut as my window handler, lately i've been thinking
I'm not a newbie since I've been programming on and off since 1983, but
In the 10 years I've been programming, I can count the number of data

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.