Jump to content

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


topflight

Recommended Posts

First time I seen this error.

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\newpilotsview.php on line 18

 

here is line 18

 

<?php
$query = mysql_query "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7" or die mysql_error());

 

Thanks in advanced!!

Link to comment
Share on other sites

Well this is the whole entire code

 


<table width="100%"  cellpadding="0" cellspacing="0">

<?php
include 'db.php';
?>


<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

$query = mysql_query "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7" or die mysql_error());
$num = mysql_num_rows($query) or die mysql_error());
?>
<table width=73% align="center">
    <tr bgcolor=#EEEEEE>
    <td width="10%">PID</td>
    <td width="15%">Name</td>
    <td width="17%">Hub</td>
    </tr>


<?php
if($nume<0){
while($data = mysql_fetch_assoc($myquery){?>


<tr bgcolor=#EEEEEE>
<tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
    <td><? echo "{$data["login"]}"?></td>
    <td><? echo "{$data["fname"]","{$data["lname"]}"?></td>
    <td><? echo "{$data["hub"]}"?></td>
    </tr>
  
</table>
<?php } ?>

Link to comment
Share on other sites

I usually do it differently anyway:

<?php
$sql = "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7";
$query = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($query) or die(mysql_error());
?>

 

Try replacing your two lines with my three.

Link to comment
Share on other sites

Now I am receiving

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\newpilotsview.php on line 34

 

this is the code

 

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);


$sql = "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7";
$query = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($query) or die(mysql_error());
?>

<table width=73% align="center">
    <tr bgcolor=#EEEEEE>
    <td width="10%">PID</td>
    <td width="15%">Name</td>
    <td width="17%">Hub</td>
    </tr>


<?php
if($nume<0){
while($data = mysql_fetch_assoc($query){?>


<tr bgcolor=#EEEEEE>
<tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
    <td><?php echo "{$data["login"]}"?></td>
    <td><?php echo "{$data["fname"]","{$data["lname"]}"?></td>
    <td><?php echo "{$data["hub"]}"?></td>
    </tr>
  
</table>
<?php } ?>

 

if I believe I need that their.

 

Line 34:

<?php while($data = mysql_fetch_assoc($query){?>

Link to comment
Share on other sites

I did that and I am still recceving the same error message. I have modified the code to looks like this now

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);


$sql = "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7";
$query = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($query) or die(mysql_error());
?>

<table width=73% align="center">
    <tr bgcolor=#EEEEEE>
    <td width="10%">PID</td>
    <td width="15%">Name</td>
    <td width="17%">Hub</td>
    </tr>


<?php 
if($nume<0){
while($data = mysql_fetch_assoc($query){?>


<tr bgcolor=#EEEEEE>
<tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
    <td><?php echo "{$data["login"]}"?></td>
    <td><?php echo "{$data["fname"]","{$data["lname"]}"?></td>
    <td><?php echo "{$data["hub"]}"?></td>
    </tr>
  <?php } ?>
</table>

Link to comment
Share on other sites

So we're perfectly clear:

 

<?php 
if($nume<0) {
    while ($data = mysql_fetch_assoc($query)) {?>
        <tr bgcolor=#EEEEEE>
        <tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
        <td><?php echo "{$data["login"]}"?></td>
        <td><?php echo "{$data["fname"]","{$data["lname"]}"?></td>
        <td><?php echo "{$data["hub"]}"?></td>
        </tr>
        <?php
    } ?>
    </table>
    <?php
}
?>

Link to comment
Share on other sites

<?php 
if($nume<0) {   // <---- Bracket ONE opened                                                                  
    while ($data = mysql_fetch_assoc($query)) {  // <---- Bracket TWO opened ?>                    
        <tr bgcolor=#EEEEEE>
        <tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
        <td><?php echo "{$data["login"]}"?></td>
        <td><?php echo "{$data["fname"]","{$data["lname"]}"?></td>
        <td><?php echo "{$data["hub"]}"?></td>
        </tr>
        <?php
    } // <---- Bracket ONE closed 
        ?>                                                                               
    </table>
    <?php
} // <---- Bracket TWO closed                                                                                       
?>

Link to comment
Share on other sites

Ok thanks all the srcipt is working but for some reason it is no showing information from the database. It is just showing the table.

 

 

<?php
$sql = "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7";
$query = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($query) or die(mysql_error());
?>

<table width=73% align="center">
    <tr bgcolor=#EEEEEE>
    <td width="10%">PID</td>
    <td width="15%">Name</td>
    <td width="17%">Hub</td>
    </tr>


<?php 
if($num<0) {   // <---- Bracket ONE opened                                                                  
    while ($data = mysql_fetch_assoc($query)) {  // <---- Bracket TWO opened ?>                   
        <tr bgcolor=#EEEEEE>
        <tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
        <td><?php echo "{$data["login"]}"?></td>
        <td><?php echo "{$data["fname"]}","{$data["lname"]}"?></td>
        <td><?php echo "{$data["hub"]}"?></td>
        </tr>
        <?php
    } // <---- Bracket ONE closed 
        ?>                                                                               
    </table>
    <?php
} // <---- Bracket TWO closed                                                                                       
?>

 

I am trying to figure out how come the information is not showing in the table. Their is stuff in the database. Please help.

 

 

I apologize for being a noob at this. PHP as so much to offer I just need to learn it, but thanks to PHP Freaks I am learning. 

 

Link to comment
Share on other sites

You are currently doing the data loop when $num < 0, you should be doing it when $num > 0:

<?php 
if($num > 0) {   // <---- Bracket ONE opened                                                                  
    while ($data = mysql_fetch_assoc($query)) {  // <---- Bracket TWO opened ?>                   
        <tr bgcolor=#EEEEEE>
        <tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
        <td><?php echo "{$data["login"]}"?></td>
        <td><?php echo "{$data["fname"]}","{$data["lname"]}"?></td>
        <td><?php echo "{$data["hub"]}"?></td>
        </tr>
        <?php
    } // <---- Bracket ONE closed 
        ?>                                                                               
    </table>
    <?php
} // <---- Bracket TWO closed                                                                                       
?>

 

Ken

Link to comment
Share on other sites

You have a problem with your if statment:

 

if $num is smaller then 0 show something?? Impossible...

 

 

This is fixed:

<?php
$sql = "SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7";
$query = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($query) or die(mysql_error());
?>

<table width=73% align="center">
    <tr bgcolor=#EEEEEE>
    <td width="10%">PID</td>
    <td width="15%">Name</td>
    <td width="17%">Hub</td>
    </tr>
   
<?php 
if($num>0) {   // <---- Bracket ONE opened                                                                  
    while ($data = mysql_fetch_assoc($query)) {  // <---- Bracket TWO opened ?>                   
        <tr bgcolor=#EEEEEE>
        <tr style="background-color:#EAEAEA;" onmouseover="this.style.backgroundColor='#0099FF'" onmouseout="this.style.backgroundColor='#EAEAEA'">
        <td><?php echo "{$data["login"]}"?></td>
        <td><?php echo "{$data["fname"]}","{$data["lname"]}"?></td>
        <td><?php echo "{$data["hub"]}"?></td>
        </tr>
        <?php
    } // <---- Bracket ONE closed 
        ?>                                                                               
    </table>
    <?php
} // <---- Bracket TWO closed                                                                                       
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.