First of all i'd like to say hello to everybody.
I've been working upon a script and i seem to be facing a problem with a mysql_query.
Here it goes:
I have 2 tables on my data base and there are some html forms through which tha data is entered in the tables. Also i got one html script as a search, where there are some radio buttons, with the same name and different values that allow the user to pick for which field he's going to give the critiria for searching.
On the php script that handles the data i have written the above:

<html>
<?PHP
$critiria=$_POST['critiria'];
$search=$_POST['search'];

$con=mysql_connect('localhost','root','');
mysql_select_db('test',$con);

if($critiria=="epitheto_iatrou"){
$sql="SELECT * FROM doctors WHERE epitheto='$critiria'";
$result=mysql_query($sql,$con) or die(mysql_error());
while ($newarray=mysql_fetch_array($result)){
echo "Epitheto: $newarray[epitheto] <br>";
echo "Eidikotita: $newarray[eidikotita]<br>";
echo "Misthos: $newarray[misthos]<br>";
}
}

else if($critiria=="eidikotita"){
$sql="SELECT * FROM doctors WHERE eidikotita='$eidikotita'";
$result=mysql_query($sql,$con) or die(mysql_error());
while ($newarray=mysql_fetch_array($result)){
echo "Epitheto: $newarray[epitheto] <br>";
echo "Eidikotita: $newarray[eidikotita]<br>";
echo "Misthos: $newarray[misthos]<br>";
}
}
else if($critiria=="epitheto_patient"){
$sql="SELECT * FROM patients WHERE epitheto='$critiria'";
$result=mysql_query($sql,$con) or die(mysql_error());
while ($newarray=mysql_fetch_array($result)){
echo "Epitheto: $newarray[epitheto] <br>";
echo "Onoma: $newarray[onoma]<br>";
echo "id_doctor: $newarray[id_doctor]<br>";
echo "date: $newarray[date]<br>";
echo "poli: $newarray[poli]<br>";
}
}
else if ($critiria='poli'){
$sql="SELECT * FROM patients WHERE poli='$critiria'";
$result=mysql_query($sql,$con) or die(mysql_error());
while ($newarray=mysql_fetch_array($result)){
echo "Epitheto: $newarray[epitheto] <br>";
echo "Onoma: $newarray[onoma]<br>";
echo "id_doctor: $newarray[id_doctor]<br>";
echo "date: $newarray[date]<br>";
echo "poli: $newarray[poli]<br>";
}
}
else if ($critiria='date'){
$sql="SELECT * FROM patients WHERE date='$critiria'";
$result=mysql_query($sql,$con) or die(mysql_error());
while ($newarray=mysql_fetch_array($result)){
echo "Epitheto: $newarray[epitheto] <br>";
echo "Onoma: $newarray[onoma]<br>";
echo "id_doctor: $newarray[id_doctor]<br>";
echo "date: $newarray[date]<br>";
echo "poli: $newarray[poli]<br>";
}
}

?>
</html>

This script returns a blanc page. I have tried the first if($critiria=="epitheto_iatrou"){
and without the if sentence, within which the mysql_query is created, the query returns the correct data.

Is there any problem with the queries if their inclosed within the commands that are to be executed in an if sentence?

Can you help me out?????

Best regards

if if($critiria=="epitheto_iatrou") this is true, then
how would the following become true.. $sql="SELECT * FROM doctors WHERE epitheto='$critiria'"; if $critiria="epitheto_iatrou" then epitheto==epitheto_iatrou , this never become true..

change your code into accordingly..

Thank you Shanti Chepuru for your implementation. I knew that i was doing something wrong but as i was all into the script trying to figure out what was the problem,icouldn't see the obvious..... that i was using the same variable in two different searches and that was TOTTALY WRONG.

Thanks again!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.