gpt4 book ai didi

php - 我已经从数据库创建了这个表。现在如果有人更新了表中的值,它如何反射(reflect)回数据库中?

转载 作者:行者123 更新时间:2023-11-28 04:54:25 25 4
gpt4 key购买 nike

我正在制作一个简单的页面来测试数据库连接。当我尝试从浏览器访问它时,它显示:

Server error

The website encountered an error while retrieving http://localhost:8888/blah/blah/test.php. It may be down for maintenance or configured incorrectly.

Here are some suggestions:

Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

我所做的只是连接到数据库并显示表格。这是我目前拥有的 PHP 代码:

<?php
// Get Variables
$dbname = $_GET["dbname"];
$dbusername = $_GET["dbusername"];
$dbpass = $_GET["dbpass"];
$dbhost = $_GET["dbhost"];






$connection = mysql_connect("$dbhost","$dbusername","$dbpass");
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "Connected";

$dbcheck = mysql_select_db("$dbname");
if (!$dbcheck) {
echo mysql_error();
}else{
echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
// Check tables
$sql = "SHOW TABLES FROM `$database`";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
echo "<p>Available tables:</p>\n";
echo "<pre>\n";
while ($row = mysql_fetch_row($result)) {
echo "{$row[0]}\n";
}
echo "</pre>\n";
} else {
echo "<p>The database '" . $database . "' contains no tables.</p>\n";
echo mysql_error();
}



}

// some code

mysql_close($con);



?>

我在 WAMP Apache 日志中的错误是:

[03-Feb-2013 22:47:37 UTC] PHP Parse error:  syntax error, unexpected end of file                              in /Applications/MAMP/htdocs/coursemanager/default/verify1.php on line 52

什么是意外的文件结尾?

最佳答案

这意味着你忘了关闭最后一个}

<?php
// Get Variables
$dbname = $_GET["dbname"];
$dbusername = $_GET["dbusername"];
$dbpass = $_GET["dbpass"];
$dbhost = $_GET["dbhost"];

$connection = mysql_connect("$dbhost","$dbusername","$dbpass");
if (!$connection) {
die('Could not connect: ' . mysql_error());
} else {
echo "Connected";

$dbcheck = mysql_select_db("$dbname");
if (!$dbcheck) {
echo mysql_error();
} else {
echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
// Check tables
$sql = "SHOW TABLES FROM `$database`";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
echo "<p>Available tables:</p>\n";
echo "<pre>\n";
while ($row = mysql_fetch_row($result)) {
echo "{$row[0]}\n";
}
echo "</pre>\n";
} else {
echo "<p>The database '" . $database . "' contains no tables.</p>\n";
echo mysql_error();
}

}
// some code
mysql_close($con);
}

关于php - 我已经从数据库创建了这个表。现在如果有人更新了表中的值,它如何反射(reflect)回数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40494558/

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