简体   繁体   中英

How to stop printing the echo statement in php?

since im using html code and the php code in the same page echo statement get print on loading the page i need to print it when the search result is empty can anyone tell what can do to stop printing the echo statement on loading the page i want to display the search result in same page so im using the html and php code in same page

<div class="container" style="border-style:solid; border-width:medium;width: 550px;">
<br/>
<form method="post">
<div class="form-group">
    Name
    <br/>
    <input type="text" class="form-control" name="name"  />
    </div>
    <div class="form-group">
   Email <br/>
   <input type="text" class="form-control"name ="email"  />
   </div>
   <div class="form-group">
    Qualification<br/>
    <input type="text" class="form-control" name ="qualify" />
    </div>
    <input type="submit" value="Search" />

</form>
<br/>
</div>
<?php
session_start();
?>

<?php
if (isset($_SESSION['message11']))
{
    echo $_SESSION['message11'];
    unset($_SESSION['message11']);
}
?>
<?php
 $servername = "localhost";
$username = "root";
$password = "root";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
   $name=$_POST['name'];
 $email=$_POST['email'];
   $qualification=$_POST['qualify'];
 $sql = "SELECT * FROM form WHERE Name ='$name' AND EmailAddress = '$email' AND Qualification = '$qualification' ";
 $result=$conn->query($sql);

 /*   if($result->num_rows === 0) 
{
  echo '<p style="margin-left:340px">no records</p>';
 } */
 //else {


  while($row = $result->fetch_assoc())
 {
    $_SESSION["snum"]=$row['sno'];
    $_SESSION["nam"]=$row['Name'];
    $_SESSION["quali"]=$row['Qualification'];
    $_SESSION["emai"]=$row['EmailAddress'];
  echo '<br>';
  echo '<form>';
  echo '<input style="margin-left:340px;padding-bottom:10px" type=checkbox>&nbsp;user Details</input>';
  echo '<br>';
  echo '<br>';
  echo '<div class="container" style="border-style:solid; border-width:medium;width: 550px;">';
  echo '<br>';
    echo 'Name: '.$row['Name']; 
    echo '<br /> EmailAddress: ' .$row['EmailAddress'];
    echo '<br /> Qualification: '.$row['Qualification'];
    echo '<br /> DOB: '.$row['DOB'];
    echo '<br/>';
    echo '<br/>';
    echo '<a href="received.php">invite</a>';
    echo '<br/>';
    echo '<br/>';
    echo '</div>';
     echo '<br/>';
    }
  //}

$conn->close();    
?>

You can add following check for showing message.

if(!empty($_POST)) {
    if($result->num_rows === 0) {
        echo '<p style="margin-left:340px">no records</p>';
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM