Page 1 of 2

trying to find out what is wrong...

Posted: Wed Mar 31, 2004 7:31 am
by EvilRadish
can someone help me with this code?

it is suposed to work (well sometimes 8O )

i can´t find what is wrong....


thanks in advance.....

<html>
<head>
<title></title>
</head>
<?php
if ($nome) {
$sql1=($nome) ? "nome like '".$nome."%'" :"" ;
}
if ($logic) {
$sql1=($nome) ? "nome like '%".$nome."%'" :"" ;
if ($nomex) {
$sql1.= ($sql1) ? " $logic " : "";
$sql1.= "telefone like '%" .$telefone. "%'" ;
}
}

if ($nome or $telefone) {
$ligação=mysql_connect("localhost", "root", "");
if (!$ligação) {
print ("Connection to MySql database error");
}
$sql="select * from teste where";
$sql.= $sql1. " order by nome asc";
print ("Database Query Results <br><br>");
$resultado = mysql_db_query ("testedb", $sql);

if ($resultado) {
$reg_pag=3;
if (!$pag) {
$pag=1;
}
$pag_ant=$pag-1;
$pag_seg=$pag+1;
$pag_ini=($reg_pag * $pag)-$reg_pag;
$num_reg=mysql_num_rows($resultado);
print ("<b> The Database Query Found $num_reg Records <p>");
print ("<table>");
print ("<tr><td>Proc</td><td>Client</td></tr>");
if ($num_reg<=$reg_pag) {
$num_pag=1;
} else if (($num_reg % $reg_pag)==0) {
$num_pag=$num_reg/$reg_pag;
}else {
$num_pag=$num_reg/$reg_pag + 1;
}
$sql=$sql." limit $pag_ini,$reg_pag";
$resultado=mysql_db_query ("testedb", $sql);
while ($registo=mysql_fetch_array($resultado)) {

$nome2=$registo["nome"];

$nome4=$registo["telefone"];

print ("<tr><td>$nome2</td><td>$nome4</td></tr>");
}
echo ("</table>");
print "page - <p>";
if (($pag_ant) && ($pag>1)) {
echo "<a .href=\"$php_self?pag=$pag_ant&nome=$nome&logic=$logic&telefone=$telefone&sql=$sql\">Previous </a>|- ";
}
for ($i=1; $i<=$num_pag;$i++) {
if($i !=$pag) {
echo "<a href=\"$php_self?pag=$i&nome=$nome&logic=$logic&telefone=$telefone&sql=$sql\">$i</a>-| ";
}else {
echo"$i -| ";
}

}
if ($pag+1 <$num_pag) {
echo "<a href=\"$php_self?pag=$pag_seg&nome=$nome&logic=$logic&telefone=$telefone&sql=$sql\"> Next </a>";
}
}else{
print ("No record found");
}
}else{
echo "Please choose the search method <br>";
echo "(blabla)<p>";

?>
<form method="post" action="<?php echo $PATH_INFO ?>">
<p align=center>Proc - <input type="text" name="nome" size="25">
<p align=center><b><input type="radio" value="and" name="logic"> e
<input type="radio" value="or" checked name="logic"> ou </b></p>
<p align=center>Client - <input type="text" name="telefone" size="12"></p>
<p align=center><input type="submit" value="search" name="Search"></p>
</form>
<?php }
mysql_free_result ($resultado);

?>
</body>
</html>

one important thing!

Posted: Wed Mar 31, 2004 7:37 am
by EvilRadish
well the result of this code should be a search facility to a database.

it´s seems to process it but the final result is:

no record found even when the name supplied in the search field exist in the database.

??

thanks

Posted: Wed Mar 31, 2004 7:44 am
by CoderGoblin
I would recommend that you output the value of the $sql variable once it is complete.
Try the select displayed yourself within MYSQL and see if that returns nothing.
If you get results then we can look more deeply at the code itself.

You need to help us help you by narrowing the error down as much as possible :wink:

Posted: Wed Mar 31, 2004 8:14 am
by Pozor
hello,

only a littel note,

your code is not very good readable, please use indention to make the code easily readable. It improve the probability of a fast and good answer...


greez Pozor

Ok

Posted: Wed Mar 31, 2004 9:43 am
by EvilRadish
OK! :lol:

Posted: Wed Mar 31, 2004 9:48 am
by JayBird
Also, please put [syntax=php][/syntax] tags around your code so the forum highlights it for you.

Thanks

Mark

Ok... here it is...

Posted: Thu Apr 01, 2004 7:37 am
by EvilRadish
Here is the code a little bit more cleaner:

Here you have the bit where it checks for the variables in the fatabase and display them if they exist.
I think it´s where the problem is... 8O

Code: Select all

$sql="select * from InfoTotal where"; 
$sql.=$sql1. " order by Client asc";

Here is the code

Code: Select all

if ($nome) {
$sql1=($nome) ? "nome like '%".$nome."%'" :"" ;
}

if ($logic) {
$sql1=($nome) ? "nome like '%".$nome."%'" :"" ;
}

if ($nome0) {
$sql1.=($sql1) ? " $logic " : "";
$sql1.= "nome0 like '%".$nome0."%'" ;
}

if ($nome or $nome0) {
$ligação=mysql_connect("localhost", "root", "");
	if (!$ligação) {
	print ("Connection to MySql database error");
		}
$sql="select * from InfoTotal where"; 
$sql.=$sql1. " order by Client asc";

print ("Database Query Results <br><br>");
$resultado = mysql_db_query ("GeneralInfo", $sql);

Then it will display the results (if any)


Here you have the search form where you will insert the keywords:

Code: Select all

<form method="post" action="<?php echo $PATH_INFO ?>">
<p align=center>Process number - <input type="text" name="nome" size="10">
<p align=center><b><input type="radio" value="and" name="logic"> and
<input type="radio" value="or" checked name="logic"> or </b></p>
<p align=center>Client name - <input type="text" name="nome0" size="25"></p>
<br>
<p align=center><input type="submit" value="search" name="Search"></p>
<br>
</form>
Thanks!

Posted: Thu Apr 01, 2004 7:48 am
by patrikG
and what's the error message?

Posted: Thu Apr 01, 2004 8:21 am
by markl999
Also note that the code requires register_globals to be On ... so might be worth checking that first.

and the error code is.....

Posted: Thu Apr 01, 2004 8:49 am
by EvilRadish
THE RESULT IS:


No records found...

even with an existing record on the database.


if i bypass the

Code: Select all

$sql="select * from InfoTotal where "; 
$sql.=$sql1. " order by Client asc";
with for example

Code: Select all

$sql="select * from InfoTotal ";

it will work just fine

yes the register_globals is on

:?

Posted: Thu Apr 01, 2004 8:50 am
by magicrobotmonkey
echo $sql right before you do the query and see what it says

?

Posted: Thu Apr 01, 2004 9:38 am
by EvilRadish
where exatly?!?!!

new guy with php here :oops:

Posted: Thu Apr 01, 2004 9:45 am
by magicrobotmonkey

Code: Select all

<?php
$sql="select * from InfoTotal where"; 
$sql.=$sql1. " order by Client asc"; 
echo "$sql"; //HERE

?>

Thanks!

Posted: Thu Apr 01, 2004 9:57 am
by EvilRadish
Thanks for your help,

the result is...

select * from InfoTotal where nome0 like '%Langaker%' order by Client asc

No record found

Posted: Thu Apr 01, 2004 10:02 am
by markl999
$resultado = mysql_db_query ("GeneralInfo", $sql); ..

mysql_db_query() is depreciated, so you should do :
mysql_select_db('GeneralInfo') or die(mysql_error());
$resultado = mysql_query($sql) or die(mysql_error());