0

MySQL

Server: mysql.mysite.com via TCP/IP Server version: 5.1.56-log Protocol version: 10 User: username@__.dreamhost.com MySQL charset: UTF-8 Unicode (utf8)

Web server

Apache MySQL client version: 5.1.66 PHP extension: mysql

phpMyAdmin

Version information: 3.3.10.4

I am at wits end right now. The exact code is currently working on the live site, but will not work for the new site I am designing.

<table>
    <tr bgcolor="#CCCCCC">

    <th>###</th>
    <th>Year</th>
    <th>Make</th>
    <th>Model</th>
    <th>Description</th>
    <th>Mileage</th>
    <th>Price</th>
    </tr>
<?

  $host = "mysql.mysite.com";
  $user = "username";
  $pass = "password";
  $dbname = "database";

  $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
  mysql_select_db($dbname);

  $sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";

  $query = mysql_query($sql);

  while ($row = mysql_fetch_array($query)) { 

    echo "<tr>
      <td></td>
      <td>",$row['year'],"</td>
      <td>",$row['make'],"</td>
      <td>",$row['model'],"</td>
      <td>",$row['dscrpt'],"</td>
      <td>",$row['miles'],"</td>
      <td>",'$',$row['price'],"</td>
      </tr>";
  }
  ?> 
</table>

I am receiving the following results on the site, both locally & when loaded on the server:

"); mysql_select_db($dbname); $sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { echo ""; } ?>

Year Make Model Description Mileage Price ",$row['year']," ",$row['make']," ",$row['model']," ",$row['dscrpt']," ",$row['miles']," ",'$',$row['price'],"

I tried a few other ways including mysqli approach, but they all yield the same results. Nothing has changed with the any of the connections and the current connection/web page still returns data. I'm going crazy looking over the code and using different code with the same results.

khaos
  • 1
  • Your new site probably has short open tags disabled. Use ` – Michael Berkowski Feb 24 '13 at 17:34
  • I actually noticed that after posting and tried the – khaos Feb 24 '13 at 17:44
  • Or your new site isn't parsing PHP at all. – Michael Berkowski Feb 24 '13 at 17:52
  • wow.. okay. I figured it out. I had to change the file extension to PHP from HTML. I tested the PHP locally and it was only displaying the code and I must not have tested it on the server. Once I loaded it to the server and changed the extension to PHP, it was displaying the rows. I spent way too much time trying to figure that out than I should have. – khaos Feb 24 '13 at 18:30

1 Answers1

1

Use <?php instead of the short open tag <?.

str
  • 42,689
  • 17
  • 109
  • 127
  • Short open tags can still be useful for when you're outputting text, e.g. `= 'hello world' ?>'. You can turn them on from php.ini, short_open_tag option (http://php.net/manual/en/ini.core.php). – Matt Browne Feb 24 '13 at 17:37
  • Or just use PHP 5.4 where `=` is always available, regardless of any settings. – str Feb 24 '13 at 17:40
  • I actually noticed that after posting and tried the – khaos Feb 24 '13 at 17:45
  • @khaos Is PHP enabled at all? – str Feb 24 '13 at 17:50
  • Okay so somewhere along the way of me testing locally and on the server, I must have changed the file extension to HTML. PHP wasn't displaying locally and I must have changed the extension. I feel really horrible that it took me that long to figure it out. But I did find other things within the code to improve on as well. Thanks for the help! – khaos Feb 24 '13 at 18:32