2012-05-11 19 views
1

私はCMSを構築するためのYouTubeチュートリアルに従おうとしています。私はそれが作成しているエラーメッセージについて本当に混乱し始めています。私は、次のエラー ます:mysqli_query()は、パラメータ1がmysqli、nullと指定されています。

は、私のコードの右側です「警告mysqli_query()がnullの7行目に/home/a8241081/public_html/index.phpで与えられ、パラメータ1はmysqliのことを期待しますか」? mysqli_select文があるはずですか?

<?php 
$db_host = "********"; 
$db_username = "******"; 
$db_pass = "*******"; 
$db_name = "********"; 
mysqli_connect("$db_host","$db_username","$db_pass", "$db_name") or die ("could not connect to mysql"); 
?> 

<?php 
session_start(); 
require_once "scripts/connect_to_mysql.php"; 

//Build Main Navigation menu and gather page data here 
$sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC"; 
$query = mysqli_query($myConnection,$sqlCommand) or die (mysqli_error($myConnection)); 

$menuDisplay=''; 
while ($row=mysqli_fetch_array($query)){ 
    $pid=$row["id"]; 
    $linklabel=$row["linklabel"]; 

    $menuDisplay .='<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br/>'; 

    } 
    mysqli_free_result($query); 
    //mysqli_close($myConnection); 
?> 

おかげ

+0

申し訳ありませんが、この質問のタイトルはあなたの問題とは何の関係もありません:あなたの現在のコード$ MyConnectionとで

は、この呼び出しで定義されていません。 –

+3

いつ人々は最終的に変数の引用をやめますか? – ThiefMaster

答えて

8

あなたは最初のブロックの最後で

$myConnection = mysqli_connect($db_host, $db_username, $db_pass, $db_name) or die ("could not connect to mysql"); 

を持つ必要があります。

$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); 
関連する問題