-1

I am trying to simply show a view in MySQL using PHP but I keep getting and error. Any advice on what the T_STRING error might be? Thanks.

Parse error: syntax error, unexpected T_STRING in /home/theaudit/public_html/_sandbox/index.php on line 14

<?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);
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
Ben
  • 1,013
  • 4
  • 16
  • 34

2 Answers2

2
$query = SELECT * FROM a_aif_remaining;

needs to be:

$query = "SELECT * FROM a_aif_remaining";
Class
  • 3,149
  • 3
  • 22
  • 31
  • That is correct. I now have another issue though... "mysql_query() expects parameter 1 to be string" – Ben Dec 24 '12 at 01:28
  • 1
    Check out hakre's answer. he removed some of the extra code and it might help you. Also you might want to check out mysqli OR PDO. mysql_* is deprecated. – Class Dec 24 '12 at 01:31
1

Get yourself a better editor and you can fix and improve your code in no time:

<?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);
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Lose the second set of calls `mysql_connect()` && `mysql_select_db()` and the OP will be in business :) – Michael Berkowski Dec 24 '12 at 01:26
  • yes and another variable was wrongly set. – hakre Dec 24 '12 at 01:26
  • @Michael. Thanks for your advice but I don't understand. What do you mean lose the second set of calls? Thanks. – Ben Dec 24 '12 at 01:30
  • @hakre what variable was that? thanks – Ben Dec 24 '12 at 01:30
  • @BenJones: Don't remember any longer, quickly fixed it, all so trivial. Let me check_ `mysql_close($con);` was it, the `$con` unset. – hakre Dec 24 '12 at 01:31
  • @BenJones In your code above, you have 2 pairs of calls to `mysql_connect()` and `mysql_select_db()`. The second set appears to be in error. I pointed that out so they could be removed from this answer. – Michael Berkowski Dec 24 '12 at 01:31
  • @hakre thanks - I see that now too... Also you may want to integrate what Michael Berkowski pointed out about the 2 pairs of calls to the mysql_connect(). I'm still not exactly sure what Michael is referring to. Thanks – Ben Dec 24 '12 at 01:41
  • Absolutely you are totally not sure it seems because it's longtime in there. Cheers.. Can anyone help? Thanks in advance. Thanks in advance . Any links to articles which may be helpful? How can I do this?? or else what will be an alternate solution for this?? Does anyone have smart solutions(algorithms) for the issue? I would appreciate your input. Thanks! Can somebody please help me with it? – hakre Dec 24 '12 at 01:44
  • 1
    What is the problem now? the extra calls to mysql_*? – Class Dec 24 '12 at 01:53
  • What part is wrong? I've opened a old project of mine and it looks much like what we have here as far as function calls w/right parameters – Class Dec 24 '12 at 01:57
  • Hello, sorry! It's all OK except for the duplicate db calls... so I updated it and removed ", $db_con" – Ben Dec 24 '12 at 05:34