topflight Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/ Share on other sites More sharing options...
Lodius2000 Posted October 10, 2008 Share Posted October 10, 2008 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 ( Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661481 Share on other sites More sharing options...
xtopolis Posted October 10, 2008 Share Posted October 10, 2008 <?php $query = mysql_query ("SELECT * FROM `pilots` ORDER BY `date` DESC LIMIT 7") or die mysql_error()); Try that, I put ( ) around "Select.....7" Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661482 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661486 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 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()); Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661488 Share on other sites More sharing options...
Lodius2000 Posted October 10, 2008 Share Posted October 10, 2008 <?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(); Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661489 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 I removed the deleted one ) from the die statement now it is just mysql_error(); and I am still receiving the error. Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661492 Share on other sites More sharing options...
xtopolis Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661502 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661507 Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 One problem is the statement while($data = mysql_fetch_assoc($myquery){?> because $myquery is never defined, and it's a closing bracket short at the end. Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661509 Share on other sites More sharing options...
xtopolis Posted October 10, 2008 Share Posted October 10, 2008 Yep, he's missing a } before </table> Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661511 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661515 Share on other sites More sharing options...
xtopolis Posted October 10, 2008 Share Posted October 10, 2008 YOU NEED ANOTHER ONE, not move the existing one! <?php } ?><!--while loop--> </table> <?php } ?><!--if statement--> Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661531 Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661552 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 I am confused I don't understand what you guys are saying. (lol) Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661555 Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 I am confused I don't understand what you guys are saying. (lol) Which bit of what I posted is confusing you? It's your code, properly indented for legibility and with loops closed. Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661567 Share on other sites More sharing options...
xtopolis Posted October 10, 2008 Share Posted October 10, 2008 "When giving someone something to copy and paste just isn't enough." Lol Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661575 Share on other sites More sharing options...
Asheeown Posted October 10, 2008 Share Posted October 10, 2008 <?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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661577 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 thanks i'll c will it work. Link to comment https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661677 Share on other sites More sharing options...
topflight Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661973 Share on other sites More sharing options...
kenrbnsn Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661977 Share on other sites More sharing options...
budimir Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127789-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-661978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.