Data not display from database in php mysql

Untitled.png

if click search button data not display but error ("Notice: Undefined index: data_id in C:\xampp\htdocs\MCS\try\ajaxData.php on line 24")

ajaxData.php code here

<?php 
require_once ("dbConfig.php");
$db_handle = new DbController();
if (($_POST["id"] =='2')) {
	$query = "SELECT DISTINCT tbl_medicine.Brand_name FROM tbl_medicine order by Brand_name asc";
	$results = $db_handle->runQuery($query);
	?>
	<option value disabled selected>Select Brand Name</option>
	<?php
		foreach ($results as $tbl_medicine) {
			?>
			<option value="<?php echo $tbl_medicine["data_id"]; ?>"> <?php echo $tbl_medicine["Brand_name"]; ?></option>
			<?php
		}
} ?>

dbConfig.php code here

<?php
class DBController{
	private $_connection;
	private static $_instance;
	private $localhost = "localhost"	;
	private $user = "root";
	private $pass = "";
	private $dbname = "druginfo";
	private $conn;
	public static function getInstance() {
		if(!isset(self::$_instance)) { // If no instance then make one
			self::$_instance = new DBController();
		}
		return self::$_instance;
	}
	public function __construct(){
		$this->_connection = $this->connectDB();
	}
	function connectDB(){
		$this->_connection = mysqli_connect($this->localhost,$this->user,$this->pass,$this->dbname);
		mysqli_set_charset($this->_connection,"utf8");
		return $this->_connection;
	}
		public function getConnection() {
		return $this->_connection;
	}
	function runQuery($query){
			$result = mysqli_query($this->_connection,$query);
			while ($row=mysqli_fetch_assoc($result)) {
				$resultset[]=$row;
			}
			if (!empty($resultset))
				return $resultset;
			}
			function numRows($query){
				$result = mysqli_query($this->_connection,$query);
				$rowcount = mysqli_num_rows($result);
				return $rowcount;
			}
		function showbrand_data(){
	$db = DBController::getInstance();
	$mysqli = $db->getConnection();
	$query = "SELECT a.Brand_name AS 'Brand Name', b.Drug_name AS 'Drug Name', tbl_medicine.data_id FROM tbl_medicine a, tbl_medicine b , tbl_medicine WHERE a.data_id ='".$_POST['SearchResult']."' AND b.data_id ='".$_POST['SearchResult']."'";
	$stmt= $mysqli->query($query);
	return $stmt;
}
}
?>

index.php code here

<form method="POST" action="medicine.php" name="search">
                    <div class="dropdown">
                        <div class="row">
                            <?php
                                include('dbConfig.php');
                                $db_handle = new DbController();
                                $choice_data=$db_handle->runQuery("SELECT * FROM choice order by search_by asc");
                                
                                ?>
                      <SELECT class="select" name="SearchBy" class="country-list" class="InputBox" onChange="getState(this.value);">
                        <option value disabled selected>Select Search_by</option>
                        <?php
                                foreach ($choice_data as $choice) {
                                ?>
                                <option value="<?php echo $choice["id"];?>"><?php echo $choice["search_by"];?></option>
                                <?php
                                }
                                ?>
                        </SELECT>
                        </div>
                        
                    <div  class="row" id="input" >
                            <select class="select" name="SearchResult" id="state-list" class="InputBox" id="data">
                                <option value="">Select Search_by first</option>                        
                            </select>
                        </div>
                    </div>
                    <button type="submit" name="submit" class="btn btn-primary btn-lg active btn-block">Search</button>
                </form>




if(isset($_POST['submit'])) {
            if(!empty($_POST['SearchBy'] == '2')){
                if(isset($_POST['SearchResult'])){
$data=$db_handle->showbrand_data();
if(mysqli_num_rows($data)){
                        ?>
                        <div class="display-data">
                        <button class="tablink" onclick="openPage('des', this, 'red')"  id="defaultOpen" style="border-top-left-radius: 10px;">Description</button>
                        <button class="tablink" onclick="openPage('dosage', this, 'green')">Indication & Dosage</button>
                        <button class="tablink" onclick="openPage('effect', this, 'blue')">Side Effect & Interaction</button>
                        <button class="tablink" onclick="openPage('company', this, 'orange')">Company Product</button>
                        <button class="tablink" onclick="openPage('warning', this, 'yellow')" style="border-top-right-radius: 10px;">Warning & Precautions</button>
                        <?php
                        while($row = mysqli_fetch_assoc($data)){
                            ?>
                    <div id="des" class="tabcontent">
                            <?php echo "<b>Brand Name:</b> ".$row['Brand Name']."<br>";?>
                            <?php echo "<b>Drug Name:</b> ".$row['Drug Name']."<br>";?>
</div>
<?php
                        }
                     }
}}}
?>



Answers 0

Related Articles