document.getElementById("n")
in the script inside php is not able to access the paragraph with id="n"
in html.
The inner html of the paragraph is not being changed.
I also tried with jQuery but it was not able to change the innerHTML
either.
<?php
$username="root";
$password="";
$servername="localhost";
$database="mydb";
$conn=mysqli_connect($servername,$username,$password,$database);
if(!($conn)){
die(mysqli_connect_error());
}
$sql="select passenger from place where source='chennai' and destination='bengaluru'";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0){
echo '<script>document.getElementById("n").innerHTML="Do Something";</script>';
}
mysqli_close($conn);
?>
<html>
<head lang="en-us">
<title>Cards</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/materialize.min.js"></script>
<script src="jquery-1.11.3.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="css/materialize.min.css">
<link rel="stylesheet" href="demo_css.css">
</head>
<body>
<p id="n"></p>
<div class="container" id="con">
<div class="card hoverable">
<div class="card-content waves-effect waves-block waves-light">
<h1 class="card-title activator grey-text text-darken-4" id="content"></h1>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Passengers<i class="material-icons right">close</i></span>
</div>
</div>
</div>
</body>
</html>