dpjuppr1361 2015-06-24 12:44
浏览 37
已采纳

将MYSQL数据从PHP传递给HTML

I have been trying to fill a HTML table with data from a MYSQL database using PHP. The problem I am having is that the placeholder values I have in the HTML file never display the data form MYSQL.

HTML file

<div class="container" style="background-image: url('http://www.MyWebSite.com/OurWorld/EditorBG.png');
-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover;
background-size: repeat; padding-bottom: 5px;">
<br />
<div class="mainbody" style="background-image: url('http://www.MyWebSite.com/Test/Notepad.png');
    background-repeat: no-repeat; margin-left: auto; margin-right: auto; margin-bottom: 10px;
    width: 646px; height: 800px !important; min-height: 100%; overflow: hidden;">
    <div class="main-form" style="margin-top: 280px; margin-left: 15px;">
        <form method="GET" action="http://www.MyWebSite./Test/SuggestionSchemeForm.php">
            <table align="center" bgcolor="white" BORDER=2 BORDERCOLOR=Black summary="Submitted Suggestions">
                <caption bgcolor="white" BORDER=2 BORDERCOLOR=Black >Submitted Suggestions</caption>
                    <thead>
                        <tr><th>Name</th><th>Site</th><th>Status</th><th>Date</th></tr>
                    </thead>
                    <tbody>
                        <tr><td><input placeholder="name"></td>   <td><input placeholder="site"></td>   <td><input placeholder="status"></td>   <td><input placeholder="date"></td></tr>
                        <tr><td><input placeholder="name"></td>   <td><input placeholder="site"></td>   <td><input placeholder="status"></td>   <td><input placeholder="date"></td></tr>
                        <tr><td><input placeholder="name"></td>   <td><input placeholder="site"></td>   <td><input placeholder="status"></td>   <td><input placeholder="date"></td></tr>
                        <tr><td><input placeholder="name"></td>   <td><input placeholder="site"></td>   <td><input placeholder="status"></td>   <td><input placeholder="date"></td></tr>            
                    </tbody>
            </table>
        </form>
    </div>
</div>

PHP File

<?php
Global $USER;
$servername = "";
$username = "";
$password = "";
$dbname = "";
$firstname = $USER->firstname;
$lastname = $USER->lastname;

$testname = "BLEGH";

echo $testname;


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) 
{
   die("Connection failed: " . $conn->connect_error);
}

$sql = mysql_query("SELECT name, site, status, date FROM enquiries")
$result = $conn->query($sql);


while($row = mysql_fetch_array($result MYSQL_ASSOC))
{
   echo "name {$row['name']}".
      "site {$row['site']}".
      "status {$row['status']}".
      "date {$row[date]}";  
}




if ($conn->query($sql) === TRUE) 
{
     echo "New record created successfully";
} 
else 
{
     echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

Header('Location: http://www.MyWebSite.com/index.php');
exit;
?> 
  • 写回答

3条回答 默认 最新

  • dongwuqi4243 2015-06-24 13:25
    关注

    You only need to use your own connection data.

    <?php
    
    //connection data
    $username = "";
    $password = "";
    $servername = "";
    $dbname = "";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s
    ", mysqli_connect_error());
        exit();
    }
    
    //select query Use ` atleast around date becasue date is a Reserved word for mysql
    if ($result = $conn->query("SELECT `name`, `site`, `status`, `date` FROM enquiries")) {
    
        while($row = $result->fetch_array(MYSQLI_ASSOC))
        {
            $suggestionsArray[] = $row;
        }
    
        /* free result set */
        $result->close();
    }
    ?> 
    
    
    <div class="container" style="background-image: url('http://www.MyWebSite.com/OurWorld/EditorBG.png');
    -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover;
    background-size: repeat; padding-bottom: 5px;">
    <br />
    <div class="mainbody" style="background-image: url('http://www.MyWebSite.com/Test/Notepad.png');
        background-repeat: no-repeat; margin-left: auto; margin-right: auto; margin-bottom: 10px;
        width: 646px; height: 800px !important; min-height: 100%; overflow: hidden;">
        <div class="main-form" style="margin-top: 280px; margin-left: 15px;">
            <form method="GET" action="http://www.MyWebSite./Test/SuggestionSchemeForm.php">
                <table align="center" bgcolor="white" BORDER=2 BORDERCOLOR=Black summary="Submitted Suggestions">
                    <caption bgcolor="white" BORDER=2 BORDERCOLOR=Black >Submitted Suggestions</caption>
                        <thead>
                            <tr><th>Name</th><th>Site</th><th>Status</th><th>Date</th></tr>
                        </thead>
                        <tbody>
    
                        <?  foreach ($suggestionsArray as $row) { ?>
                                    <tr><td><? echo $row['name']; ?></td>   <td><? echo $row['site']; ?></td>   <td><? echo $row['status']; ?></td>   <td><? echo $row['date']; ?></td></tr>
    
                        <?  } ?>
    
    
    
                        </tbody>
                </table>
            </form>
        </div>
    </div>
    
    <?  $conn->close();  ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图