0

I am trying to display 3 tables on one page.

I'm using 3 different queries, but it’s giving me an error on the second query. I'm assuming this isn't a syntax error, but it could be. Let me know if you need any more details.

The code,

<?php
session_start();
if ($_SESSION['loggedin'] != "YES")
{
    header("location:index.php?problem=notLoggedIn");
}
$name = $_SESSION['username'];
?>
<html>
<div style="width: 80%; margin-left:auto; margin-right:auto;">
<div style="float: right;">Welcome <? print($name); ?></div>
<?php 
//Connect to MSSQL Server
$myServer = ".\MSSQLSERVER2008";
$myUser = "admin";
$myPass = "password";
$myDB = "database"; 

//connection to the server
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

  //select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");  

$result = mssql_query("SELECT *
FROM table1
INNER JOIN table4
ON table1.user_id=table4.user_id;");
if(!$result){
//echo 'Failed to receive data. Please try again, or contact support.';
}
else{
//echo 'Successfully received data.';
//$results = mssql_query($result);
//var_dump($results);
}
?>
<center>
<table border='1'>
    <tr>
        <th>Name of Center</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Name_of_Center'] . "</td>"; }
        mssql_data_seek($result, 0); ?> 
    </tr>
    <tr>
        <th>Contact Name</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Contact_Name'] . "</td>"; }
        mssql_data_seek($result, 0); ?> 
    </tr>
    <tr>
        <th>Title</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Title'] . "</td>"; }
        mssql_data_seek($result, 0); ?> 
    </tr>
    <tr>
        <th>Street Address</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Street_Address'] . "</td>"; }
        mssql_data_seek($result, 0); ?> 
    </tr>
    <tr>
        <th>City</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['City'] . "</td>"; }
        mssql_data_seek($result, 0); ?>
    </tr>
    <tr>
        <th>State</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['State_or_Province'] . "</td>"; }
        mssql_data_seek($result, 0); ?>
    </tr>
    <tr>
        <th>Zipcode</th>
        <?php while($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Zipcode'] . "</td>"; }
        mssql_data_seek($result, 0); ?>
    </tr>
    <tr>
        <th>Instructions</th>
        <?php while ($row = mssql_fetch_array($result)) {
        echo "<td>" . $row['Instructions'] . "</td>"; }
        mssql_data_seek($result, 0); ?>
    </tr>
</table>

<?php//insert form results into database
$result2 = mssql_query("SELECT *
FROM table2
INNER JOIN table4
ON tale2.user_id=table4.user_id;");
if(!$result2){
//echo 'Failed to receive data. Please try again, or contact support.';
}
else{
//echo 'Successfully received data.';
//$results = mssql_query($result);
//var_dump($results);
}?>

<table border='1'>
    <tr>
        <th>Last Name 1</th>
        <?php while($row2 = mssql_fetch_array($result2)) {
        echo "<td>" . $row2['Last_Name_1'] . "</td>"; }
        mssql_data_seek($result2, 0); ?>    
    </tr>
    <tr>
        <th>First Name 1</th>
        <?php while($row2 = mssql_fetch_array($result2)) {
        echo "<td>" . $row2['First_Name_1'] . "</td>"; }
        mssql_data_seek($result2, 0); ?>    
    </tr>
    <tr>
        <th>Mobile Phone 1</th>
        <?php while($row2 = mssql_fetch_array($result2)) {
        echo "<td>" . $row2['Mobile_Phone_1'] . "</td>"; }
        mssql_data_seek($result2, 0); ?>    
    </tr>
    <tr>
        <th> 3 Work Phone</th>
        <?php while($row2 = mssql_fetch_array($result2)) {
        echo "<td>" . $row2['Work_Phone_3'] . "</td>"; }
        mssql_data_seek($result2, 0); ?>    
    </tr>
    <tr>
        <th>3 Email</th>
        <?php while($row2 = mssql_fetch_array($result2)) {
        echo "<td>" . $row2['Email_3'] . "</td>"; }
        mssql_data_seek($result2, 0); ?>    
    </tr>
</table>

<?php//insert form results into database
$result3 = mssql_query("SELECT *
FROM table3
INNER JOIN table4
ON table3.user_id=table4.user_id;");
if(!$result3){
//echo 'Failed to receive data. Please try again, or contact support.';
}
else{
//echo 'Successfully received data.';
//$results = mssql_query($result);
//var_dump($results);
}?>

<table border='1'>
    <tr>
        <th>Insured Name</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Insured_Name'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>
    <tr>
        <th>Policy Number</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Policy_Number'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>
    <tr>
        <th>Specimen Number 5</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Specimen_Number_5'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>
    <tr>
        <th>Specimen Number 6</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Specimen_Number_6'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>
    <tr>
        <th>Premium 24</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Premium_24'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>   
    <tr>
        <th>Premium 25</th>
        <?php while($row3 = mssql_fetch_array($result3)) {
        echo "<td>" . $row3['Premium_25'] . "</td>"; }
        mssql_data_seek($result3, 0); ?>    
    </tr>
</table>
</center>
<style>
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    text-indent: 1px;
    text-overflow: '';
}

select::-ms-expand {
    display: none;
}

td a:link {
 color:  white;
}

td a:visited {
 color: white;
} 

td a:active {
 color: white; 
} 
</style>

</html>

Here's the error:

Parse error: syntax error, unexpected T_VARIABLE

For This Line:

$result2 = mssql_query("SELECT *
4
  • Have you run this query in the database tools? Commented May 5, 2014 at 19:03
  • I've run the queries by themselves and they've worked. I'm having an issue with there being more than one being run on a single page. Commented May 5, 2014 at 19:06
  • are you sure you have (<?) php short tag enabled? Commented May 5, 2014 at 19:11
  • I do think that your way of populating columns is pretty convoluted, but that is for another day. Can you output any other error data? If not, can you find the error in the logs to see if it is more detailed? Commented May 5, 2014 at 19:14

2 Answers 2

1

Your JOIN clause in the $result2 query includes " ON tale2.user_id=table4.user_id; " . I assume you mean table2.user_id rather than tale2.user_id? In fact, it's more than an assumption, since you're selecting from table2, not tale2. (I would have included this as a comment but don't have the reputation level yet.)

Sign up to request clarification or add additional context in comments.

1 Comment

The name of the tables were just placeholders for the actual names. My bad on the typo. Thanks for pointing it out.
0

Change this:

<?php//insert form results into database
$result3 = mssql_query("SELECT *

...to this:

<?php
//insert form results into database
$result3 = mssql_query("SELECT *

Edit: There should at least be a space between <?php and code or a comment (after the last p).

In not doing so, will cause a parse error.

Invalid: <?php// comment

Invalid: <?phpecho "Hello";

As opposed to:

Valid: <?php // comment

Valid: <?php echo "Hello";

6 Comments

This would not solve the OP's problem or answer his question. Why is this important?
Yeah, so this totally worked. Thanks so much. -2 on this answer? So much hate on Stacksonstacksonstacksoverflow.
Actually @JayBlanchard having the <?php// comments will cause a parse error. Try this <?php//comment echo "hey"; and see the result.
Ah - he said keep code away (which was done). Comments != code.
True, yet it's debatable, but it's not my battle ;-) @JayBlanchard yet it was the answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.