Jump to content

Need help to select and display data from DB


vsnair

Recommended Posts

Hi all,
     I am a php student and i am doing a project in php. I am doing the project of online attendance register. I am stuck with the part of reports. We need to select three different values from an HTML form and pick the selected rows and wants to display those rows in a table. I have done a code but it is not working. Please help me out of this issue. HTML Form:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

</head>



<body><form action="reportpro.php" method="get"    name="services">

  <table width="447" border="0" align="center" >

    <tr style="text-align: center">

      <td width="441"><table width="481" border="1">

        <tr>

          <td width="216"><div align="center">

            SECTION

          </div></td>

          <td width="102"><div align="center">

            MONTH

          </div></td>

          <td width="141"><div align="center">

            YEAR

          </div></td>

           

        </tr>

        <tr>

          <td><select name="section" id="select">

            <option>SERVICES-A</option>

            <option>SERVICES-B</option>

            <option>SERVICES-C</option>

            

          </select></td>

          <td><select name="month" id="select">

            <option>01</option>

            <option>02</option>

            <option>03</option>

            <option>04</option>

            <option>05</option>

            <option>06</option>

            <option>07</option>

            <option>08</option>

            <option>09</option>

            <option>10</option>

            <option>11</option>

            <option>12</option>

          </select></td>

          <td><select name="year" id="select">

            <option>2014</option>

            <option>2015</option>

            <option>2016</option>

            <option>2017</option>

            <option>2018</option>

            <option>2019</option>

            <option>2020</option>

            </select></td>

            

    </tr>

            

          

        

        <tr>

          <td colspan="4">  <center><input name="submit" type="submit" id="submit"   formaction="reportpro.php" formmethod="get" value="Search"></center></td>

          </tr>

      </table>

        <p> 

          

        </p>

        <p>   

        </p>

      <p> 

      </p></td>

    </tr>

  </table>

</form>

</body>

</html>


PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>



<body>



<form action="" method="get">

  <table border="1" align="center" >

 

    <tr>

      <td>BOOK NO</td>

      <td>Name</td>

      <td>Desigination</td>

      <td>Section</td>

      <td>Day</td>

       <td>Month</td>

        <td>Year</td>

         

      <td>Attendance</td>

      </tr>

    

    <?php

$con=mysql_connect("localhost","root","");

mysql_select_db("niy",$con);



$m=$_REQUEST['month'];

$y=$_REQUEST['year'];

$sec=$_REQUEST['section'];



 $sql="select month='$m', year='$y', sectn='$sec' from attendance ";

echo $sql;



$res=mysql_query($sql,$con);

while($row=mysql_fetch_array($res))

{

?>

<tr>

   <td><?php echo $row[1];?></td>

<td><?php echo $row[2];?></td>

<td><?php echo $row[3];?></td>

<td><?php echo $row[4];?></td>



  <td><?php echo $row[5];?></td>

  <td><?php echo $m;?></td>

  <td><?php echo $y;?></td>  

    <td><?php echo $row[8];?></td>

     

 

 </tr>

  <?php

  }

  ?>

 

    

   </table>

</body>

</html>

Link to comment
Share on other sites

For the benefit of those not members of the other forum ...

 

RTFM re SELECT query syntax.

$sql="select month='$m', year='$y', sectn='$sec' from attendance ";

should be

$sql="select <whatever> from attendance 
         WHERE month='$m' AND year='$y' AND sectn='$sec'";

Also:

    stop using mysql_ functions and use mysqli_ or PDO functions

    don't put user data directly into your queries. Use prepared statements.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.