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 value that allows the user to pick for which field he's going to give the critiria of searching.
On the php script that handles thw date i have written the above:

<html>
<?PHP
$critiria=$_POST;
$search=$_POST;
$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 AND without the if sentences, within which the mysql_query if created, the query returns the correct data.

Can you help me out?????

Best regards

Member Avatar for diafol

USe [ CODE ] for code. This is difficult to read.

you are missing double-equals on

else if ($critiria='poli'){

and on

else if ($critiria='date'){

as a start.

Try this:
1. Why don't create a page where your sql connection is coded. For example, create a php script and save it as connection.php and here is the code for it.

<?php
    	error_reporting(0);

	$connection = Mysql_connect('localhost','root','');
	mysql_select_db('test'); //test is the name of your database.
?>

Now analyze the modification that I made in this code.

<?PHP
      error_reporting(0);
      session_start();
      include 'connection.php' // call the connection for your database.

$critiria=$_POST['critiria'];
$search=$_POST['search'];

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

else if($critiria=="eidikotita"){
$sql=mysql_query("SELECT * FROM doctors WHERE eidikotita='$eidikotita'");
while ($newarray=mysql_fetch_array($sql)){
echo "Epitheto: $newarray['epitheto'] <br>";
echo "Eidikotita: $newarray['eidikotita']<br>";
echo "Misthos: $newarray['misthos']<br>";
}
}
else if($critiria=="epitheto_patient"){
$sql=mysql_query("SELECT * FROM patients WHERE epitheto='$critiria'");
while ($newarray=mysql_fetch_array($sql)){
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=mysql_query("SELECT * FROM patients WHERE poli='$critiria'");
while ($newarray=mysql_fetch_array($sql)){
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=mysql_query("SELECT * FROM patients WHERE date='$critiria'");
while ($newarray=mysql_fetch_array($sql)){
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>";
}
}

?>

The above query should work, but if not, try to eliminate "else" on "else if". Just make

if($critiria=="something")
{
  //blah blah blah
}
if($critiria=="something")
{
   //blah blah blah
}

First of all thank you for your answers.
1. on my code there are double equals.
2. To lyrico => I have tried what you said and there was no data retrieved from the query. The problem seem to be when include the mysql_query within the {} of the if sentence. The query alone works properly.
Is there any incompatibility among the mysql code when used within an if sentence?

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>";
}

Those are NOT double equals.I guess.

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.