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

标签 php html css

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

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/

相关文章:

html - 将 HTML 文本框中的某个单词加粗

php - 转到不同页面时菜单栏闪烁

CSS 相对定位和填充

PHP:按键对 JSON 数据进行排序

php - 在 CodeIgniter 中添加新页面

javascript - 在弹出窗口处于事件状态时禁用滚动

jquery - 我应该如何删除动态添加的文本框

php - 当条件相同时,如何对多列使用一次 CASE 语句?

php - 单例结构

css - firefox 如何决定使用哪些@-moz-document 规则?