-1

我正在尝试使用 PHP 在 MySQL 中简单地显示一个视图,但我不断出错。关于 T_STRING 错误可能是什么的任何建议?谢谢。

解析错误:语法错误,第 14 行 /home/theaudit/public_html/_sandbox/index.php 中的意外 T_STRING

<?php

// connection parameters
$db_host="a";
$username="b";
$password="c";
$db_name="d";

// connection variables
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);

// page variables
$query = SELECT * FROM a_aif_remaining;
$result = mysql_query($query);

// connection to mysql and db 
mysql_connect($db_con) or die("Unable to connect to MySQL");
mysql_select_db($db_name) or die("Unable to select database");

// successful result

echo "<table border=1>
        <tr>
        <th>aif</th>
        <th>fee_source</th>
        <th>company_screename</th>
        <th>filing_date</th>
        <th>document_subtype</th>
    </tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['aif_id'] . "</td>";
  echo "<td>" . $row['fee_source_id'] . "</td>";
  echo "<td>" . $row['company_name_per_sedar'] . "</td>";
  echo "<td>" . $row['document_filing_date'] . "</td>";
  echo "<td>" . $row['document_subtype'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
4

2 回答 2

2
$query = SELECT * FROM a_aif_remaining;

需要是:

$query = "SELECT * FROM a_aif_remaining";
于 2012-12-24T01:22:08.353 回答
1

让自己成为一个更好的编辑器,您可以立即修复和改进您的代码:

<?php

// connection parameters
$db_host = "a";
$username = "b";
$password = "c";
$db_name = "d";

// connection variables + connection to mysql and db
$db_con = mysql_connect($db_host, $username, $password);
$result = mysql_select_db($db_name, $db_con);

// page variables
$query = 'SELECT * FROM a_aif_remaining';
$result = mysql_query($query, $db_con);

// successful result
echo '<table border=1>
    <tr>
    <th>aif</th>
    <th>fee_source</th>
    <th>company_screename</th>
    <th>filing_date</th>
    <th>document_subtype</th>
</tr>';

while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['aif_id'] . "</td>";
    echo "<td>" . $row['fee_source_id'] . "</td>";
    echo "<td>" . $row['company_name_per_sedar'] . "</td>";
    echo "<td>" . $row['document_filing_date'] . "</td>";
    echo "<td>" . $row['document_subtype'] . "</td>";
    echo "</tr>";
}
echo "</table>";

mysql_close($db_con);
?>
于 2012-12-24T01:23:30.770 回答