2015-11-02 82 views
-1
<?php 

$dbcon=mysqli_connect("localhost","root","","simple_login"); 

mysqli_select_db($dbcon,""); 

?> 

上面的代碼是在db_conection.php沒有mysqli的數據庫中選擇錯誤

在另一個文件中我嘗試accesss稱爲校表

if(!$_SESSION['username']) 
{ 

    header("Location: index.php");//redirect to login page to secure the welcome page without login access. 
} 
else 
{ 
$user=$_SESSION['username']; 
    require('db_conection.php'); 
    $ex0=mysql_query("SELECT * FROM school WHERE uid='$user'") or die(mysql_error()); 
       $count=mysql_num_rows($ex0); 
       if($count) 
       { 
       echo '<script>'; 
       echo 'alert("Profile there");'; 
       echo '</script>'; 
       } 
} 
?> 

即使需要()之後,它會引發錯誤未選擇數據庫。請幫忙。

+0

所以,**選擇一個數據庫**吧? http://php.net/manual/en/mysqli.select-db.php –

+0

可能重複[沒有數據庫選擇錯誤信息](http://stackoverflow.com/questions/16418870/no-database-selected-error -信息) –

回答

0

嘗試檢查連接並粘貼一條消息,如果死

$dbcon=mysqli_connect("localhost","root","","simple_login") or die ("Connection error!!!"); 

maeby你需要MySQL服務器

上連接如一通,你爲什麼把第二排的連接如?

和1點一刻......如果包括礦石連接如到DB更好的主意需要thefile是聲明DB連接如變量如全球 例如:

$host = "localhost"; 
$user = "root"; 
$pass= ""; 
$db = "simple_login"; 
$GLOBALS['connect'] = mysqli_connect($host, $user, $pass, $db) or die ("Connection error!!!"); 
mysqli_set_charset ($GLOBALS['connect'], "utf8"); 
unset($host,$root,$pass,$db); 

在查詢後連接到只有$ DB GLOBALS [ '連接'];

include(my_conection_file.php); 
mysqli_query($GLOBALS['connect'],"AND HERE INPUT YOUR QUERY"); 

,如果你用的mysqli conected您querys必須是庫MySQLi而不是MySQL的全髖關節置換是你的問題conetion與mysqli_connect和查詢的mysql_query