alim1990
alim1990

Reputation: 4972

Unable to take values from drop down list

I need to get values from drop down list and query them into other SQL command to fetch final data into a table. I have this code, but nothing is displayed in the table when the submit button is clicked. Actually, the table disappears and nothing is shown.

         <?php
require_once('../include/global.php');
?>
<!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>
<div class="">
<form action="" method="submit">
<select name="Date" required class="form-control" id="Date">
    <option value="">Please Select Date</option>
    <?php $sql2="SELECT * FROM clinic.appoint GROUP BY date";
    $result2 = mysqli_query($con, $sql2) or die($sql2."<br/><br/>".mysql_error());
    while($rows2=mysqli_fetch_array($result2)){?>
    <option value="<?php echo $rows2['date'] ?>"><?php echo $rows2['date'] ?></option>
    <?php } ?>
</select>
<input type="submit" name="submit" value="Select Date" />
</form>
<?php
if(isset($_POST['submit'])){ 
          if(isset($_POST['Date'])){ 


          $selectOpt =$_REQUEST['Date'];
$sql="SELECT * FROM clinic.appoint WHERE date='".$selectOpt."' ";
$result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error());
$rows=mysqli_fetch_array($result);
}
else{
        $sql."<br/><br/>".mysql_error();
}
?>
<table>
<th>Time</th>
<th>Name</th>
<tr>
<td><?php echo $rows['time'] ?></td>
<td><?php echo $rows['name'] ?></td>
</tr>
</table>
<?php } ?>
</div>
</body>
</html>

Upvotes: 0

Views: 57

Answers (1)

Shaymol Bapary
Shaymol Bapary

Reputation: 458

Just copy and paste on your page the full code and change the database info

I think It will work for you

 <?php
define("DB_HOST", "db_host");
define("DB_USER", "db_user");
define("DB_PASSWORD", "db_pass");
define("DB_DATABASE", "db_name");
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_DATABASE );
?>
<script language="javascript" type="text/javascript">
var selectSearch = document.getElementById('Date').value;

selectSearch.onchange = function() {
  window.location = selectSearch[selectSearch.selectedIndex].value;
};
</script>
</head>

<body>
<div class="container12">
  <header>
    <div align="center">
      <div class="column12"> <a href="homepage.php"><img src="images/logo.png"/></a> </div>
    </div>
    <div align="center">
            <div align="center"><a href="logout.php">Logout</a></div>
    </div>
  </header>
  <h1 id="home">&nbsp;</h1>
  <div class="alert"></div>
  <div class="column12" align="left"><B><center>Appointments</B></center><br />
  </div> 
    </div>
  </div>
</div>
<div class="container12" align="center">
<form action="addApp.php" method="post" name="form1" id="form1">
<table width="700px" class="imagetable" align="center">
<th align="center">Name</th>
<th>Date</th>
<th>Time</th>
<th>Contact Number</th>
<th>Action</th>
<tr>
<td><input type="text" name="name" class="large-fld-app" placeholder="name"/></td>
<td><input type="text" name="date" class="large-fld-app" placeholder="DD/MM/YYYY"/></td>
<td><input type="time" name="time" class="large-fld-app"/></td>
<td><input type="text" name="phone" class="large-fld-app"/></td>
<td align="center"><input type="submit" value="" name="submit" class="imgClass_save" />
</td>
</tr>
</table>
</form>
</div>
<?php
$sql="SELECT * FROM clinic.appoint";
$result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error());
$rows=mysqli_fetch_array($result)
?>
<div class="container">
<table>
          <thead>
            <tr>
                            Schedule               

              <th scope="row">
                    <form action="" method="submit">
                    <select name="Date" required class="form-control" id="Date">
    <option value="">Please Select Date</option>
    <?php $sql2="SELECT * FROM clinic.appoint";
    $result2 = mysqli_query($con, $sql2) or die($sql2."<br/><br/>".mysql_error());
    while($rows2=mysqli_fetch_array($result2)){?>
    <option value="<?php echo $rows2['id'] ?>"><?php echo $rows2['name'] ?></option>
    <?php } ?>
</select>
<input type="submit" name="submit" value="Select Date" />
</form>
              </th>
              <td class="schedule-offset" colspan="2">
              </td>
            </tr>
          </thead>
          <tbody>
          <?php if(isset($_REQUEST['submit'])){ ?>
          <?php if(isset($_REQUEST['Date'])){ ?>

          <?php
          $selectOpt = $_REQUEST['Date'];
          $sql="SELECT * FROM clinic.appoint WHERE date='".$selectOpt."' ";
          $result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error());

?>
            <tr>
            <?php while($rows=mysqli_fetch_array($result)){?>
              <th scope="row">


                <?php echo $rows['time'] ?>
              </th>
              <td scope="row" id="scheduleDate">
                <?php echo $rows['name'] ?>
              </td>
              <td scope="row">
                <?php echo $rows['date'] ?>
              </td>
                          <?php } ?>

            </tr>
            <tr>
            <?php }?>
            <?php }?>
              <th scope="row">
                <time datetime="14:00">2:00 PM</time>
              </th>
              <td>
                <a href="speakers.html#tessa-harmon">
                  <h4>Tessa Harmon</h4>
                  Crafty Coding: Generating Knitting Patterns
                </a>
              </td>
            </tr>
          </tbody>
        </table>
</div>


</body>
</html>

Upvotes: 1

Related Questions