sturobinson81 Posted March 10, 2014 Share Posted March 10, 2014 Hi, newbie programmer here. Trying to get the following code working, but i keep getting an error. Probably something stupid, or maybe just my lack of knowledge can post error message if it would help. Any help very much appreciated <?php include 'connect.php'; $result = mysqli_query($con,"SELECT * FROM pdfs WHERE Keywords LIKE '%stu%'"); while($row = mysqli_fetch_array($result)) { $pdf=$row['FILENAME']; echo $row['Keywords']; echo "<br>"; echo $row['FILENAME']; echo "<br>"; header("Content-type: application/pdf"); header("Content-Disposition: inline; filename=$pdf"); readfile($pdf); } mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 Yes - what is the error message? Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 16 stu test2 newsite/pdfs/test2.pdf Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 16 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 You must ensure that you are not outputting anything prior to your header call. That includes even a single space character or blank line. That is what the messages are telling you. Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 ah... does that include the echo statements that show the 'stu test2' part? I've omitted the first occurrence from the message above as i didn't think it was relevant. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 What do you think? I though my post was pretty direct, as in: " That includes even a single space character or blank line.". Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 or is it refering to the echo statement in my connect.php file? / Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 fair enough... Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 10, 2014 Share Posted March 10, 2014 That echo will only occur if there is an error which should interrupt your script. I would add an exit() line to that connect file since I wouldn't want to continue with my script if my connection was not available. Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 I still get the following errors... Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:12) in /home/bictech/public_html/newsite/search2.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:12) in /home/bictech/public_html/newsite/search2.php on line 9 %PDF-1.3 %âãÏÓ 4 0 obj << /Type /Page /Parent 2 0 R /Contents 10 0 R /MediaBox [0.0000 0.0000 1190.5512 841.8898] /TrimBox [0.0000 0.0000 1190.5512 841.8898] /CropBox [0.0000 0.0000 1190.5512 841.8898] /Resources << /ProcSet [/PDF /ImageC /Text /ImageB] /XObject << /Im12 12 0 R /Im49 49 0 R /Im50 50 0 R /Im70 70 0 R /Im71 71 0 R >> /Font << /F13 13 0 R /F17 17 0 R /F21 21 0 R /F25 25 0 R /F30 30 0 R /F34 34 0 R /F38 38 0 R /Symb 43 0 R /F51 51 0 R /F55 55 0 R /F60 60 0 R /F65 65 0 R /F72 72 0 R >> /ExtGState << /GS11 11 0 R >> /ColorSpace << /CS48 48 0 R >> >> >> endobj 10 0 obj << /Filter [/FlateDecode ] /Length 4415 >> stream xÚÕ[É’7z¾3‚ݢØ9Ø^lRÉ´G#zØÖÅò!»*»+GU•ÅZšn=ˆŸÃ‡ŸÀbŸýþ²è¬^bd˜¡(d&ðã_¿)VQÿ‡Ðâ¿,ûÿôŸÙêù³ßýð1r½{þìãógšºJSFå Œ•LrrÎd%8wá/Bª°Í»ãäm÷üÙ?Ž÷ÄçÚQòëógþS.ðŽUÑœ` and a lot more garbage... anything im doing obviously wrong? Quote Link to comment Share on other sites More sharing options...
sturobinson81 Posted March 10, 2014 Author Share Posted March 10, 2014 my current code ------------------------------------------------ ------------------------connect.php-------------------------- <?php// Create connection$con=mysqli_connect("bictechnology.co.uk","bictech_stu","bictech2014","bictech_pdfdb"); // Check connectionif (mysqli_connect_errno()) { echo "Failed to connect to MySQL:" . mysqli_connect_error(); exit(); }?> --------------------------------------------------- ---------------------search2.php---------------------- <?phpinclude 'connect.php';$result = mysqli_query($con,"SELECT * FROM pdfsWHERE Keywords LIKE '%stu%'");while($row = mysqli_fetch_array($result)) { $pdf=$row['FILENAME']; header("Content-type: application/pdf"); header("Content-Disposition: inline; filename=$pdf"); readfile($pdf); }mysqli_close($con);?>-------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 10, 2014 Share Posted March 10, 2014 did you read the error messages? you have output on line 12 of connect.php. that line is the closing ?> tag. you likely have some characters after the ?>. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.