Division by Zero Warning
I have programmed a search form with three fields and the one that is giving me problems is the one that uses 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>
// 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 is this error repeated twice?
Warning: Division by zero in .. on line ..
Warning: Division by zero in .. on line ..
I don't do the division ... me?
Thanks in advance
0
a source to share
2 answers
Yes Yes. The characters %
used LIKE
are behind the line and are therefore interpreted as a modulo operator. Remove additional characters.
$queryStr .= "tbl_clientes WHERE nome LIKE '%$nome%'";
(I used a mixture of single and double quotes here to solve the problem. Eoin Campbell 's solution to escape inner single quotes is also true. That you will need to use (a combination of) these methods when programming in PHP.)
+10
a source to share