javascript - Notice: Use of undefined constant database_name - assumed 'database_name' in C:\xampp\htdocs\visitor\index.php on line 97 -


please assist me; making page able see visitors of website through ip addresses using php, javascripts msql, getting lot of errors when try execute codes below. not know issue here. please help! here errors getting:

notice: use of undefined constant database_name - assumed 'database_name' in c:\xampp\htdocs\visitor\index.php on line 97

warning: mysql_num_rows() expects parameter 1 resource, boolean given in c:\xampp\htdocs\visitor\index.php on line 105

warning: mysql_num_rows() expects parameter 1 resource, boolean given in c:\xampp\htdocs\visitor\index.php on line 119

warning: mysql_num_rows() expects parameter 1 resource, boolean given in c:\xampp\htdocs\visitor\index.php on line 137

warning: mysql_num_rows() expects parameter 1 resource, boolean given in c:\xampp\htdocs\visitor\index.php on line 144

please help!

<!doctype html>   <head>     <title>visitor counter</title>     <style>         *{margin: 0px;             padding: 0px;         }          body{text-align: center;             width: 66%;             margin: auto;             /*background: url(images/background.jpg);*/             background-color: green;             font-family: helvetica, arial, sans-serif;         }          h1{             font-family: helvetica, arial, sans-serif;             text-align: center;             font-size: 60px;             margin-top: 80px;             color: #000;             text-shadow: 2px 2px 0px rgba(255,255,255,.7), 5px 7px 0px rgba(0,0,0,0.1);         }          .container{height: 250px;             width: 31%;             float: left;             margin-top: 40px;         }          .round{             width: 160px;             height: 160px;             border-radius: 50%;             background: #fff;             margin: 20px auto;         }          .values{             color: #888;             line-height: 3.8em;             font-size: 40px;         }          p{             font-size: 32px;             color: #fff;             font-weight: bold;         }       </style>      <script type="text/javascript" src="js/jquery.min.js" ></script>       <script src="js/jquery-3.2.1.min.js"></script>   <script src="js/jquery-2.2.4.min.js"></script>     <script type="text/javascript">         $(document).ready(function(){             setinterval(function()             {                 $.ajax                 ({                     type: 'post',                     url:'',                     data:{                         get_online_visitor:"online_visitor",                      },                     success:function(response){                         if(response!="")                         {                             $("#online_visitor_val").html(response);                         }                      }                  });             }, 10000)         });     </script>  </head> <body>  <?php session_start(); $_session['session']=session_id();  $host="localhost"; $username="root"; $password=""; $databasename="visitor"; $connect=mysql_connect($host, $username, $password); $db=mysql_select_db(database_name);  function total_online() {     $current_time=time();     $timeout = $current_time - (60);      $session_exist = mysql_query("selecct session total_visitors session='".$_session['session']."'");     $session_check = mysql_num_rows($session_exist);      if($session_check==0 && $_session['session']!="")     {         mysql_query("insert total_visitors values ('', '".$_session['session']."','".$current_time."')");      }     else     {         $sql = mysql_query("update total_visitors set time='".time()."' session='".$_session['session']."'");      }      $select_total = mysql_query("selecct * total_visitors time>= '$timeout'");     $total_online_visitors = mysql_num_rows($select_total);     return $total_online_visitors; }  if(isset($_post['get_online_visitor'])) {     $total_online=total_online();     echo $total_online;     exit(); } ?>  <?php //to total online visitors $total_online_visitors=total_online();  //to total visitors $total_visitors = mysql_query("select * total_visitors"); $total_visitors = mysql_num_rows($total_visitors);  //to insert page view , select total page view $user_ip=$_server['remote_addr']; $page=$_server['php_self']; mysql_query("insert pageviews values('','$page','$user_ip')"); $pageviews = mysql_query("select * pageviews"); $total_pageviews = mysql_num_rows($pageviews); ?>  <div class="container">     <div class="round"><p class="values"><?php echo $total_visitors;?></p></div>     <p>total visitors</p>  </div>  <div class="container">     <div class="round"><p class="values" id="online_visitor_val"><?php echo $total_online_visitors;?></p></div>     <p>online visitors</p>  </div>  <div class="container">     <div class="round"><p class="values"><?php echo $total_pageviews;?></p></div>     <p>total page views</p>  </div>   </body> </html> 

in code u not assigning correct database name using php variable

your code

$db=mysql_select_db(database_name); 

correct code

$db=mysql_select_db($databasename);

you can check sql error in php using mysql_error ()

 $sql ="select session total_visitors session='".$_session['session']."'";   echo $sql;   /* check sql in phpmyadmin*/  $session_exist = mysql_query($sql) or die(mysql_error ());` 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -