gpt4 book ai didi

php - 简单的 PHP 获取表中的所有数据不起作用

转载 作者:行者123 更新时间:2023-11-29 08:08:12 26 4
gpt4 key购买 nike

好吧,我不知道到底发生了什么,我只是想列出表中的所有数据,但它不起作用我尝试了几种不同的方法,但没有收到任何错误消息我已经多次讨论过语法了。

这是代码:

// Connect to database
$dbc = mysql_connect("localhost", "root");
if (!$dbc)
die("Could not connect" . mysql_error());

// Select database
$dbc_dbselect = mysql_select_db( "contactmanager", $dbc );
if (!$dbc_contactmanager)
die("Could not connect: " . mysql_error());

// Query database
$query = "SELECT * FROM contacts ORDER by name";

$result = mysql_query($query);

// start a table tag in the HTML
echo '<table>';

// Create a loop to loop through results
while($row = mysql_fetch_array($result)){

// Print the results
echo '<tr>'.'<td>'.$row['Name'].'</td>'.'<td>'.$row['Address'].'</td>'.'<td>'.$row['Phone'].'</td>'.'<td>'.$row['Mobile'].'</td>'.'<td>'.$row['Mobile'].'</td>'.'</tr>';
}

echo "</table>"; //Close the table in HTML


mysql_close($dbc);

这是在firefox中的输出结果:

 '; //Create a loop to loop through results while($row = mysql_fetch_array($result)){ echo ''.''.$row['Name'].''.''.$row['Address'].''.''.$row['Phone'].''.''.$row['Mobile'].''.''.$row['Mobile'].''.''; //$row['index'] the index here is a field name } echo ""; //Close the table in HTML mysql_close($dbc); ?> 

数据库和表 This is the Database and table

最佳答案

我认为您缺少第三个参数,即:密码

$dbc = mysql_connect("localhost", "root", "");
^----Here

应该是:

mysql_select_db( "contactmanager", $dbc );

关于php - 简单的 PHP 获取表中的所有数据不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22293363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com