0

I am not sure what is going wrong with my code. I am getting message "Page isn't working" not sure why ? I am trying to fetch details of filter on "retrieve1.php" but each time i try to click on student filter i am getting a message saying "Page isn't working". I would appreciate any help here.

<?php

 echo "<body style='background-color:#DCDCDC'>";

include ("account.php");
( $db = mysql_connect( $hostname, $username, $password ))
    or die ( "unable to connect to MYSQL database" );
mysql_select_db( $project );



$sql= "SELECT * FROM bpi_registration LEFT JOIN 
bpi_schoolInfo on bpi_registration.id_school = bpi_schoolInfo.id_school";
     

$query=mysql_query($sql) or die(mysql_error());



function grade()
{
 $query= "select distinct class_name from bpi_classInfo";
 $result=mysql_query($query) or  die(mysql_error());
  
  
 while  ($value = mysql_fetch_array ($result))
 {
 echo "<option value='" . $value['class_name'] . "'>" . $value['class_name'] . "</option>";
 }


}



function school()
{
 $query= "select distinct school_name from bpi_schoolInfo";
 $result=mysql_query($query)or  die(mysql_error());
  
  
 while  ($value = mysql_fetch_array ($result))
 {
  echo "<option value='" . $value['school_name'] . "'>" . $value['school_name'] . "</option>";
 }


}




function team()
{
 $query= "select distinct team_name from bpi_teamProfile";
 $result=mysql_query($query)or  die(mysql_error());
  
  
 while  ($value = mysql_fetch_array ($result))
 {
  echo "<option value='" . $value['team_name'] . "'>" . $value['team_name'] . "</option>";
 }


}



function students()
{
 $query= "select * from bpi_registration";
 $result=mysql_query($query)or  die(mysql_error());
  
  
 while  ($value = mysql_fetch_array ($result))
 {
  echo "<option value='" . $value['first_name'].' '.$value['last_name']. "'>" . $value['first_name'].' '.$value['last_name']. "</option>";
  
 }


}


?>



<form action="retrieve1.php" method="GET">

<select name="Grade">
<option value="" selected="selected">Choose Grade</option>
<?php grade() ?>
</select>

<select name="School">
<option value="" selected="selected">Choose School</option>
<?php school() ?>
</select>

<select name="Team">
<option value="" selected="selected">Choose Team</option>
<?php team() ?>
</select>

<select name="Students">
<option value="" selected="selected">Choose Students</option>
<?php students() ?>
</select>

<input type="submit" value="Find" />
</form>



<table width="600" border="2">  
<tr>  
<th width="91"> <div align="center">First Name </div></th>  
<th width="98"> <div align="center">Last Name </div></th>  
<th width="198"> <div align="center">Email </div></th>  
<th width="97"> <div align="center">City </div></th>  
<th width="97"> <div align="center">State </div></th>  
<th width="59"> <div align="center">Country </div></th>   
<th width="59"> <div align="center">View </div></th>   


<tr>

<?php
if (isset($_GET['Students']))
{
while ($row=mysql_fetch_array($query))
{ 


    echo $row['email'];
    echo $row['address_city'];
    echo $row['address_state'];
    echo $row['address_country'];
  

  }




}


?>
jon doe
  • 9
  • 6
  • Have you written this yourself or just copy-pasted it? – Ikari Mar 27 '16 at 06:58
  • @Saitama why this strange question ? To answer your question - most of the part i am watching videos on youtube and following the code. Nothing has been copy pasted here. Everything is self-learning – jon doe Mar 27 '16 at 06:59
  • Your code layout was terrible, try using some tabs? also you have not closed your tag, just opened another one. Consider using an IDE or something like sublime text – Tim Ogilvy Mar 27 '16 at 07:18
  • @TimOgilvy i am new to php I appreciate your feedback. I am using textwrangler – jon doe Mar 27 '16 at 07:25
  • Going beyond the basics, you are using php mysql which is incredibly outdated, (see PDO and MySQLI) and your php code is procedural rather than object orientated. Also have a read of https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php. Having said that, you are making a good start. Good luck! – Tim Ogilvy Mar 27 '16 at 07:29

2 Answers2

0

You are writing a wrong code on select. Use the below one.

<form action="retrieve1.php" method="GET">

<select name="Grade">
<option value="" selected="selected">Choose Grade</option>
<?php grade() ?>
</select>

<select name="School">
<option value="" selected="selected">Choose School</option>
<?php school() ?>
</select>

<select name="Team">
<option value="" selected="selected">Choose Team</option>
<?php team() ?>
</select>

<select name="Students">
<option value="" selected="selected">Choose Students</option>
<?php students() ?>
</select>

<input type="submit" value="Find" />
</form>

and also you are missing curly brace end of while loop

<?php
if (isset($_GET['Students']))
{
    while ($row=mysql_fetch_array($query))
    {
        echo $row['email'];
        echo $row['address_city'];
        echo $row['address_state'];
        echo $row['address_country'];
    }
}
?>
Ajay
  • 235
  • 2
  • 8
0

You are missing }

<?php
if (isset($_GET['Students']))
{
    while ($row=mysql_fetch_array($query))
    {
        echo $row['email'];
        echo $row['address_city'];
        echo $row['address_state'];
        echo $row['address_country'];
    }
}
?>
Thiyagesan
  • 75
  • 6