尝试使用 PHP 和 MySQL 制作一个非常简单的 CMS,无法获取数据输出
我试图为个人项目的网站制作一个非常简单的 CMS。这是我第一次使用 MySQL,也是我第一次使用 PHP,所以这是一次学习经历。不过,根据我问过的每个人的说法,这应该有效。然而,它输出的只是。我已经检查了数据库和表上的所有内容,列名是正确的。我还没有尝试将任何内容添加到数据库中。我只想能够阅读,但即使是简单的概念验证也行不通。
如果重要的话,我使用 000webhost 作为我的网络托管。
<?php
$mysql_host = "****";
$mysql_database = "****";
$mysql_user = "sql_blog";
$mysql_password = "*****";
$link = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!mysql_select_db($mysql_database, $link)) {
echo 'Database error';
exit;
}
$sql_statement = ('SELECT * FROM Blog_Entries');
$result = mysql_query($sql_statement);
while ($curr_row = mysql_fetch_assoc($result)) {
echo '<h1>' . $result['Title'] . '</h1>';
}
mysql_free_result($result);
?>
大部分代码是从 http: //guy-lecky-thompson.suite101.com/build-a-blog-or-cms-with-php-a55246 但就像我说的,看起来应该可以工作......
I was trying to make a VERY simple CMS for a website for a personal project. It's my first time using MySQL, and one of my first using PHP, so it's kind of a learning experience. According to everybody I've asked, though, this should work. However, all it outputs is the <h1></h1>
. I've checked everything on my database and table, the column names are right. I'm not trying to make anything to add to the database just yet. I just want to be able to read, and even a simple proof-of-concept isn't working.
If it matters, I'm using 000webhost for my web hosting.
<?php
$mysql_host = "****";
$mysql_database = "****";
$mysql_user = "sql_blog";
$mysql_password = "*****";
$link = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!mysql_select_db($mysql_database, $link)) {
echo 'Database error';
exit;
}
$sql_statement = ('SELECT * FROM Blog_Entries');
$result = mysql_query($sql_statement);
while ($curr_row = mysql_fetch_assoc($result)) {
echo '<h1>' . $result['Title'] . '</h1>';
}
mysql_free_result($result);
?>
Most of that code is copied from http://guy-lecky-thompson.suite101.com/build-a-blog-or-cms-with-php-a55246 but like I said, it looks like it should work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 while 循环中有错误。
应该是
当您迭代行时,您需要使用该行,而不是指向结果集的指针。
You have an error in your while loop.
Should be
When you iterate through the rows you need to use the row, not the pointer to the resultset.
更改为:
Change to:
您需要更改
为
$result 是查询返回的整个结果集的句柄。 $curr_row 是您从结果集中提取的行。
You need to change
to
$result is the handle to the entire result set that your query returned. $curr_row is the row you've pulled out of the result set.
更改
为
Change
to