doulu7258 2013-11-24 09:01
浏览 81
已采纳

PHP-MySQL数据库连接

I'm learning PHP with videos of lynda.com.I created a database called widget_corp in my localhost phpmyadmin panel and I wrote these code block

    <?php
/* 1.Create a database connection */
$connection = mysql_connect("localhost", "root", "*");
if(!$connection){
die("Database connection failed: " .mysql_error());
}

/* 2. Select a database to use */
$db_select = mysql_select_db("widget_corp", $connection);
if(!$db_select)
{
die("Database selection failed: " . mysql_error());
}
?>

    <html>
    <head>
    <title> Connection To the Database </title>
    </head>
    <body>
    <?php

//3. Perform database query
$result = mysql_query("SELECT * FROM subjects",$connection);
if(!$result)
{
die("Database query failed: " .mysql_error());
}

//4. Use returned data

while($row = mysql_fetch_array($result));
{
echo $row["menu_name"]." ".$row["position"]."<br/>";
}
?>
</body>
</html>
<?php
//5. Close connection
mysql_close($connection);
?>

I always get this error type:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.4 (Unix) PHP/5.5.3 OpenSSL/1.0.1e mod_perl/2.0.8-dev Perl/v5.16.3

How can I overcome this issue? thanks all

  • 写回答

1条回答 默认 最新

  • douyi1963 2013-11-24 11:19
    关注

    You made a very small mistake. You used a semicolon in while statement, so just remove it. Then it will work fine.

    Use returned data:

    while($row = mysql_fetch_array($result))
    

    Not:

     while($row = mysql_fetch_array($result));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗