错误代码:
Notice: Undefined variable: blog_array in /home/willconnor/public_html/index.php on line 69
* 创建博客数组 */$blog_array = array();
<?php
if(sizeof($blog_array) > 0)
{
/*** loop over the blog array and display blogs ***/
foreach($blog_array as $blog)
{
echo '<div class="blog_entry">';
echo '<p><span class="category">'.$blog['blog_category_name'].': </span>
<span class="blog_date">Added by '.$blog['blog_user_name'].' on '.$blog['blog_content_date'].'</p>';
echo '<h2>'.$blog['blog_content_headline'].'</h2>';
echo '<p>'.$blog['blog_content_text'].'</p>';
echo '</div>';
}
}
else
{
echo 'No Blogs Here';
}
/*** include the footer file ***/
include 'includes/footer.php';
?>
错误代码:
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /home/willconnor/public_html/includes/conn.php on line 16
<?php
/*** mysqli hostname ***/
$hostname = 'localhost';
/*** mysqli username ***/
$username = 'username';
/*** mysqli password ***/
$password = 'password';
/*** connect to the database ***/
$link = mysqli_connect($hostname, $username, $password);
/*** select the database ***/
$db = mysqli_select_db('blog', $link);
?>
最佳答案
尝试如下
/*** mysqli hostname ***/
$hostname = 'localhost';
/*** mysqli username ***/
$username = 'username';
/*** mysqli password ***/
$password = 'password';
$con=mysqli_connect($hostname,$username,$password,"blog");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
如果你想改变选择的数据库“blog”那么你只需要写下一行
mysqli_select_db($con,"replace_selected_db");
关于php - 为什么我会收到这些错误? php 和 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34689992/