sql - Php count registered users -


i learning php , creating basic site "control panel". right i'm encountering error code while attempting amount of registered users. database:

-- phpmyadmin sql dump -- version 4.2.12deb2+deb8u2 -- http://www.phpmyadmin.net -- -- host: localhost -- generation time: jul 25, 2017 @ 06:10 pm -- server version: 5.5.55-0+deb8u1 -- php version: 5.6.30-0+deb8u1  set sql_mode = "no_auto_value_on_zero"; set time_zone = "+00:00";   /*!40101 set @old_character_set_client=@@character_set_client */; /*!40101 set @old_character_set_results=@@character_set_results */; /*!40101 set @old_collation_connection=@@collation_connection */; /*!40101 set names utf8 */;  -- -- database: `login` --  -- --------------------------------------------------------  -- -- table structure table `users` --  create table if not exists `users` ( `user_id` int(11) not null,   `user_uname` varchar(256) not null,   `user_email` varchar(256) not null,   `user_pwd` varchar(256) not null ) engine=innodb auto_increment=2 default charset=latin1;  -- -- dumping data table `users` --  insert `users` (`user_id`, `user_uname`, `user_email`, `user_pwd`) values(1, 'test1', 'johndoe@mail.com', 'hashedpassword');  -- -- indexes dumped tables --  -- -- indexes table `users` -- alter table `users`  add primary key (`user_id`);  -- -- auto_increment dumped tables --  -- -- auto_increment table `users` -- alter table `users` modify `user_id` int(11) not null auto_increment,auto_increment=2; /*!40101 set character_set_client=@old_character_set_client */; /*!40101 set character_set_results=@old_character_set_results */; /*!40101 set collation_connection=@old_collation_connection */; 

the index.php file

<?php  include dbh.inc.php;  ?>  <html>  <head>  	<title>sidebar-test</title>  	<link rel="stylesheet" type="text/css" href="css/style.css">  	<link rel="stylesheet" type="text/css" href="css/flaticon.css">  </head>  <body>  <div id="header">  	<div class="logo"><a href='#'>side<span>source</span></a></div>  </div>  <div id="container">      <div class="sidebar">      <ul id="nav">        <li><span class="flaticon-graphic"></span><a href="#">dashboard</a></li>        <li><span class="flaticon-download"></span><a href="#">download</a></li>        <li><span class="flaticon-settings-work-tool"></span><a href="#">settings</a></li>      </ul>    </div>    	<div class="content">  		<h1>dashboard</h1>  		<div id="box1" class="box">  		<h3>users</h3>  		<p id="box1p">  <?php  $sql = "select count(user_id) registered_users users";  $result = mysqli_query($conn, $sql) or die ("query error!");      while ($row = mysqli_fetch_array($result)) {        $var = $row['registered_users'];        echo "there " .$var. " users.";    }  ?>  		</div>  	</div>  	  </div>  </body>  </html>

and dbh.inc.php:

<?php    $dbservername = "localhost";  $dbusername = "root";  $dbpassword = "";  $dbname = "login";    $conn = mysqli_connect($dbservername, $dbusername, $dbpassword, $dbname);    if (!$conn) {  	die("connection failed: " . mysqli_connect_error());  }

i've tried error-reporting mysqli_report(mysqli_report_error | mysqli_report_strict); returned nothing, entering select count(user_id) registered_users users in phpmyadmin return registered_users 1. appreciated!

$sql = "select count(user_id) registered_users users"; $var = $row['count']; 

you select count as registered_users you're trying read field count not exist. use $row['registered_users'] instead.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -