php html在xampp上本地工作,但在上传时不能

时间:2017-07-18 19:58:28

标签: php mysql

我有一个php文件,我知道某处有错误。在我的本地机器上用xampp使用它时工作正常,但是当上传到主机时,我得到标题和导航,然后它从我的PHP代码的检查连接部分说“错误获取”,并且不会制作桌子。其他页面工作正常并提交到数据库,所以我假设connect.php页面是正确的,其代码是错误的。我的讲座也告诉我,这是代码,但我很难找到问题

<?php
       //uses the connect.php file to connect to the database
         include('connect.php')

 ?>

 <!DOCTYPE html>
     <html>
        <head>
          <title>Extract data from DB </title>

          <link rel="stylesheet" type="text/css" href="gcards.css">

        </head>

        <body>


        <nav class="nav">
           <h1>Gcards </h1> 
           <a href="get.php">Gcards</a>
           <a href="insert.php">INSERT</a>
           <a href="delete.php">DELETE</a> 
        </nav>

 <?php

   //query the database to extract relavent data
     $get= "SELECT * FROM manufacturer 
                   join 
         rating on manufacturer.manufacturerID = Rating.RatingID
                   join
         model on manufacturer.manufacturerID = model.ModelID
                   join
        ram on manufacturer.manufacturerID = ram.RamID
                   join
        ram_type on manufacturer.manufacturerID = Ram_Type.Ram_TypeID           
                   join
        clock on manufacturer.manufacturerID = clock.ClockID";

    // check connection
    $data = mysqli_query($dbconnect, $get) or die('error getting');

         echo "<table class=\"display\">";
         echo "<tr><th>ID</th>
         <th>Image_Url</th>
         <th>Manufacturer</th>
         <th>Series</th>
         <th>Interface</th>
         <th>Chipset</th>
         <th>SLI-Cross Fire</th>
         <th>Ram</th>
         <th>Ram Type</th>
         <th>Clock_Speed</th>
         <th>Boost_Speed</th>
         <th>OC_Speed</th></tr>";


     while ($row = mysqli_fetch_array($data, MYSQLI_ASSOC)) {
                     echo "<tr>";
                     echo "</td><td>";
                     echo $row['ManufacturerID'];
                     echo "</td><td>";
         ?>


               <img src ="<?php echo $row['Image_Url']; ?>" 
                    height="100" width="125">
            <?php                
                     echo "<br>";
                ?>
                     <img src ="<?php echo $row['Rating']; ?>" width="125">
            <?php
                     echo "</td><td>";
                     echo $row['Manufacturer'];
                     echo "</td><td>";
                     echo $row['Series'];
                     echo "</td><td>";
                     echo $row['Interface'];
                     echo "</td><td>";
                     echo $row['Chipset'];
                     echo"</td><td>";
                     echo $row['SLI_Crossfire'];
                     echo"</td><td>";
                     echo $row['RamNo'];                           
                     echo "</td><td>";
                     echo $row['Ram_Type'];
                     echo"</td><td>";
                     echo $row['Clock_Speed'];
                     echo"</td><td>";
                     echo $row['Boost_Speed'];
                     echo"</td><td>";
                     echo $row['OC_Speed'];
                     echo "</td></tr>"; 
                    echo "</table>";    
                                    }
                  ?>


         </body>
      </html>

2 个答案:

答案 0 :(得分:2)

您的本地XAMPP到远程服务器的MySQL(或MariaDB)配置似乎可能存在冲突。请注意,出于开发目的,XAMPP MySQL配置比大多数Linux安装上的设置稍微宽松一些。

因此,要找到您的错误,请修改您的代码以输出MySQL错误。

更改$data = mysqli_query($dbconnect, $get) or die('error getting');

if (!$data = mysqli_query($dbconnect, $get)) {
    printf("Errormessage: %s\n", mysqli_error($dbconnect));
    exit;
}

这将输出MySQL正在抛出的实际错误,并帮助您了解SQL中的问题。它也可能揭示更多。

PHP: mysqli::$error - Manual

答案 1 :(得分:0)

XAMPP通常在Windows上运行,这里mysql在大多数情况下不区分大小写,这意味着select * from MYTABLE;select * from mytable;是相同的。您的主机可能运行一些unix系统,上面的示例将查询来自不同表的数据。

所以plz看看你的查询,即。您有一个表ram_type以及之后的Ram_Type,它们应该完全按照它们的定义来编写。

请参阅https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html