php - 将 MySQL 行导入表中

标签 php html mysql

所以我将一些 MySQL 行导入到表单中,但似乎有一个问题,数据库无法连接,它说没有选择数据库,我的数据库连接参数在 Constants.php 中,它们在另一个中工作正常网站页面,命令中也没有语法错误,请帮助我。谢谢!

<?php
    require_once 'classes/Membership.php';
    require_once 'includes/constants.php';
    $membership = New Membership();
    $membership->confirm_Member();
    $con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
    die('Error connecting Database');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <title>Post Scores | Admin Panel D2C</title>
        <style type="text/css">
        </style>
    </head>

    <body>
        <div class="main_body">

        <table width="1029" border="0" cellpadding="0" class="score_table" >
            <td width="131">
            <form align="center" action="update_team_database.php" method="post">
            <tr>

            <td> Team: </td>
            <td width="831">

            <?php 
                $result = mysql_query("select DISTINCT TeamName from team") or die(mysql_error());
                echo '<select name="teamname1"><OPTION>'; 
                echo "Select a team</OPTION>"; 
                while ($row = mysql_fetch_array($result)){
                $team1 = $row["TeamName"]; 
                echo "<OPTION value=\"$team1\">$team1</OPTION>";     
            } 
            echo '</SELECT>';
            ?></td>

            </tr>
            </form>
        </table>
    </body>
</html>

最佳答案

我建议您使用面向对象的方式使用MySQLi通过MySQL执行查询

您可以在这里查看示例 http://in2.php.net/manual/en/mysqli.query.php

由于 MySQL 从 PHP 5.5 开始已被弃用

关于php - 将 MySQL 行导入表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21186272/

相关文章:

javascript - 从特殊链接重新加载到另一个页面后如何运行功能?

php - Apache Solr 转义查询

javascript - 覆盖这个类的字体大小 .MuiTypography-body1

php - 当我们上传时,如何减少 codeigniter 中图像的文件大小(以 kb 为单位)?

带路径的 JavaScript 图形可视化

php - 无法以管理员身份登录 WordPress

php - 如何使用 CodeIgniter DB Forge 生成createdAt 和updatedAt 时间戳/日期时间?

php - 求助php解析错误

php - PHP 错误消息 "Notice: Use of undefined constant"是什么意思?

php - 在跳过缩写的同时将驼峰大小写格式化为可读的 PHP