Click here to Skip to main content
15,746,534 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php


include("admin/config/db.php");

$get=$_GET['text'];

?>

<html>
<head>

<link type="text/css" rel="stylesheet" href="assest/bootstrap.min.css" >
 


<link href="assest\fontawesome-free-5.11.2-web\css\fontawesome.min.css" rel="styleheet">
<link rel="stylesheet" type="text/css" href="\IIHH\assest\style.css">
</head>

<body class="main">

<div class="container" style="background:white">
    <br>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="index.php">IIHH</a>
    </div>

    <ul class="nav navbar-nav  menu1">
      <li><a href="index.php">Home</a></li>
      <li><a href="about.php">About Us</a></li>
      <li><a href="contact.php">Contact Us</a></li>
    </ul>
   
</nav>
<div class="row">

  <h1 class="heading">International <span class="active"> Institute of Health & Hygiene</span> </h1>


  </div>
<br>

<div>
<nav class="navbar navbar-inverse" style="width:px;">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="index.php"><img src="image/home.png" style="width:30px; height:22px;"></a>
    </div>

    <ul class="nav navbar-nav menu">
      <li><a href="index.php">Latest News</a></li>
      <li><a href="all.php">All News</a></li>
          <li><a href="search.php">Search</a></li>
    </ul>
   
  </div>
</nav>

<div class="row">

	<div class="col-md-8">



		<img src="admin/image/1.png" class="img img-thumbnail" style="width:100%; height:300px; padding:10px;">
	


		<div class="post">

      
			<div class="row">



<div class="side">
		<div class="post_main">
			<span> Result</span>
</div>
<br><br>
<br>

<div class="msg" style="margin:10px;">
<h5 style="float:right;">

<?php




$select="select * from news where Name like '%$get%'";
$run=mysqli_query($con, $select);
$count=mysqli_num_rows($run);
if($count>0){


?>


  Your search Result<span class "badge"> <?php echo $count?> Found</span></h5>
</div>



<?php   


while($row=mysqli_fetch_array($run)){

$id=$row['id'];
$name=$row['Name'];
$img=$row['Image'];
$text=$row['Text'];
$date=$row['Date'];



?>
<div class="col-md-4">
	
<img src="admin/image/<?php echo $img?>" class="img-img-thumbnail" width="200px" height="150px" style="border:1px solid;">

</div>


<div class="col-md-8">

	<br><h4 style="font-weight: bold; color:#333333;"><?php echo $name?></h4>
<h6 style="float:right;">Date:<?php echo $date?></h6><br><br>
<p style="text-align:justify; margin-left:12px;">
  

<?php echo $text?>

</p>
</div>
</div>
<?php
}
}


else{

  echo "<script>window.open('search.php?msg=Result Not Found','_self')</script>";
}
?>

</div>

<div class="col-md-4">
	<div class="side">
		<div class="side_main">
			<span>Latest Post</span>
</div>
</div>
<div class="row">
<div class="col-md-4"><br><img src="admin/image/3.png"  class ="img img-rounded" style="width:120px; height:120px; border:1px solid;"><br><br></div>

<br><br><br><div class="col-md-8"><span class="side_post"><a href="#">News Website is</a></div>
</div>
</div><hr>

<div class="col-md-4">
	<div class="side">
		<div class="side_main">
			<span>Categories</span>
</div>
</div>
<div class="cat">
	<a href="#">World Hleath Organisation </a>
	<a href="#">Moef&CC</a>
	<a href="#">United Nation</a>
</div>
</div>
</div>
</div>
<div class="footer">
	<center><h5 style="font-weight:bold; line-height: 35px;"><p>© 2019 Powered by IIHH<p></h5></center>
</div>
</div>
</body>


</html>


What I have tried:

I have already defined the variable of the text, only then the error message is giving the undefined index text please help me to correct the mistake, and I am pasting the result code.
Notice: Undefined index: text in C:\xampp\htdocs\IIHH\result.php on line 6
Posted
Updated 22-Oct-19 7:33am

Check the DB that you query:
$select="select * from news where Name like '%$get%'";
$run=mysqli_query($con, $select);
...
while($row=mysqli_fetch_array($run)){
...
$text=$row['Text'];
...
The error is saying that the query returned no column called "text" - which means your table news does not have a column of that name to return.
 
Share this answer
 
PHP
$select="select * from news where Name like '%$get%'";

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900