$data= mysql_query("select * from tbl_files where sl.no=1");
$rec= mysql_fetch_row ($data)
echo $rec[1];


Parse error: syntax error, unexpected 'header' (T_STRING) in C:\xampp\htdocs\readfromdb.php on line 6

2 Years
Discussion Span
Last Post by diafol

sorry i didn't get you, can you pls elaborate it briefly ???


line 5 semicolon
line 6 semicolon

without the semicolon terminating line 5, line 6 is determined to continue line 5, and is not semantically correct
fix it,
then fix line 6 or you will get the same error referring to line 7 next run

@ David_50
would have been the answer, if sl.no were outside of quotes in Mysql_query(), inside quotes refers to DB structure already defined.
Went to note on your post,
doing that downgrades post,
not fair for what would usually be correct,
wrote here instead

Edited by almostbob


You need to define sl, such as a table of the from clause: ... from tbl_files sl where sl.no = ...

Not sure what sort of database structure mysql allows you to refer to without a from clause anchor. If sl is a column of some advanced datatype, then I suppose you could dot into the innards.

Edited by David_50


Is there any reason that you're using deprecated code?

Use PDO/mysqli - mysql_* functions are dead. Don't use them.


Of course, the error is pointing to your header line, which is not the mormal line. Did you want to concatenate the constant 'content-type:' with the variable string $rec[2]? http://php.net/manual/en/language.operators.string.php says try:

header( "content-type:" . $rec[2] );

Semicolons also seem to be missing, as mentioned above. Linefeeds are not so magic in webby languages.


To be pedantic, the reason for the error as mentioned a number of times is the missing ';' on line 5 of your supplied code. However, as pointed out previously there is another omission: semi-colon on line 6.

The SQL:

select * from tbl_files where sl.no=1

Looks a bit squiffy to me too.

If you have a column named 'sl.no', which is not advisable, then you'd have to wrap this name within backticks in order to distinguish it from a table 'sl' - which is not defined elsewhere in your query. So

SELECT * FROM tbl_files WHERE `sl.no` = 1

should work for a column called sl.no. Otherwise the query should fail. It may be a typo on your part and should be sl_no? My 2p - but I'm no expert.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.