-2

I have a php file, and i know there is an error somewhere. When using this on my local machine with xampp it works fine, but when uploaded to a host, i get the header, and nav, then it says 'error getting', from the check connection part of my php code, and won't produce the table. the other pages work fine and submit to the data base so i assume the connect.php page is correct and its the code thats wrong. i have also been told by my lecture that it is the code, but i am struggling to find the problem

<?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>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 2
    What's the full error? – Daniel Jul 18 '17 at 19:59
  • theres no error that comes up it just wont, show the table when i direct to the site page. $data = mysqli_query($dbconnect, $get) or die('error getting'); – Chris Jul 18 '17 at 20:03
  • 2
    I have to ask: were the credentials updated to match the host authentication? (and not still set to your local config?) – Paul T. Jul 18 '17 at 20:05
  • No problem, i was kind of expecting that question. Yes all was changed i even went and added 2 new users to the database in phpmyadmin to check if that was the issue. and changed accordingly in the connect.php file – Chris Jul 18 '17 at 20:07
  • Typically hosting services hide errors to prevent security issues with people knowing what software you're using under the hood. For development purposes though, you may want to temporary add error handling to your PHP file on your host. If you're not seeing anything, you're probably getting an error but the server is swallowing it. See [this question](https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings) for help in configuring the errors to show... – War10ck Jul 18 '17 at 20:10

2 Answers2

2

It seems you may have a conflict with your MySQL (or MariaDB) configuration from your local XAMPP to your remote server. Please note, for development purposes XAMPPs MySQL configuration is a little looser than found on most linux installs.

So, to find your error please modify your code to output the MySQL error.

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

To

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

This will output the actual error MySQL is throwing and help you understand your issue within your SQL. It may also reveal more.

PHP: mysqli::$error - Manual

Zakky
  • 139
  • 6
0

XAMPP usually runs on windows, here mysql is in most cases case insensitive, meaning select * from MYTABLE; and select * from mytable; are the same. Your host probably runs some unix-system, there the above example would query data from different tables.

so plz have a look in your query, ie. you have once table ram_type and later Ram_Type, they should be exactly written as how they are defined.

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

Norman M
  • 243
  • 1
  • 9