我使用的是include函数。我想知道它的使用水平。说到点子上,我有一个名为hitcounter.php的页面,我想知道在我的应用程序中有多少人点击了该页面。所以我创建了hitcounter.php
我的问题是,我在我的一个页面中包含了这个hitcounter.php,我想知道那个特定的点击率,并将其存储在数据库中。在hitcounter.php中,我包含了dbconnection.php.When,我登录到了我的应用程序中,然后我访问了包含hitcounter.php的特定页面,它显示错误:没有选择数据库。
在我2.8年的经验中,我第一次得到这个错误,我谷歌了很多次,但我没有找到这个问题的答案。
我的hitcountercode代码:
include"dbconnection.php";
//Adds one to the counter
mysql_query("UPDATE counter SET patient_dashboard = patient_dashboard + 1")or die (mysql_error());
//Retreives the current count
$count = mysql_fetch_row(mysql_query("SELECT patient_dashboard FROM counter"))or die(mysql_error());
//Displays the count on your site
print "$count[0]";这就是我包含hit counter.php的方式
<?php include"../includes/subpageheader.php";
include"../includes/hitcounter.php";
?>mydatabase连接代码:
$conn=mysql_connect('localhost','root','');
//echo $conn."<br/>";
$db=mysql_select_db('health');我想知道我们在php中使用了多少层的include函数。
那么,如何解决这个错误,有没有人可以帮我。
发布于 2012-07-02 16:03:12
在我看来,你的错误与include无关,问题是你没有选择数据库,看看这个例子:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>https://stackoverflow.com/questions/11289705
复制相似问题