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!!

any time i get a parse error, i check the line above to make sure it has a semicolon before i do anything else

 

edit: especially if the word "unexpected" is in the error

 

also mysql_query is a function and you have no opening (

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 } ?>

Now I am receiving this error message

 

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

 

 

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

 

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

 

Try that, I put ( ) around "Select.....7"

 

if you are going to put ...7") you need to make the or die clause: or die mysql_error();

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.

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){?>

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>

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
}
?>

<?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                                                                                       
?>

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. 

 

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

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                                                                                       
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.