inkzoid Posted August 30, 2010 Share Posted August 30, 2010 I've got a comment box that is functioning correctly and is set up to a database to retrieve and display comments, but what I am trying to do is place it on a different page. I want it on my gallery.php page, and when I try to include it, I get one of those header errors because it isn't included immediately on line 1. I know I can solve the problem by including it on line 1, but I want my comment box somewhere else down the page and don't know what I have to do to put it somewhere else. <?php @session_start(); // calling session_start() the function which starts our authentication session // connecting to mysql server $l = mysql_connect ( "999.999.999.999" , "inkzoid" , "999" ) or die("Error connecting:<BR><BR>".mysql_error()); mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error()); // defining getShouts() which is our function that gets all of our shouts function getShouts() { echo '<div align="left"> <table width="800" bgcolor="#128911" border="0" cellspacing="0" cellpadding="0"> <tr> <td> '; $query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_array($query) ) { //print_r($row); $name = stripslashes($row['name']); $contact = stripslashes($row['contact']); $shout = stripslashes($row['shout']); if(empty($contact)) { echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>'; } else { echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>'; } // if empty contact } // while row mysqlfetcharray query echo '<br><br>'; echo ' </td> </tr> <tr> <td height="10"> </td> <form name="shout" method="post" action="shout.php"> <div align="center"> <input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br> <input name="contact" type="text" id="contact" value="http://" size="25"><br> <input name="message" type="text" id="message" value="Message" size="25"><br> <input name="shout" type="submit" id="shout" value="Shout!"> </div> </form> </td> </tr> </table> </div> '; } // function getshouts // our processing if control statement if ( isset ( $_POST['shout'] ) ) { $name = addslashes($_POST['name']); $contact = addslashes($_POST['contact']); $message = $_POST['message']; if ( ( isset($name) ) && ( isset($message) ) ) { // getting smilie list $smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error()); while($get = mysql_fetch_array ($smilies)) { $alt = $get['Alt']; $smilie = $get['URL']; $message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message); $themessage = addslashes($message); // replacing all smilies } mysql_query("INSERT INTO shouts (name, contact, shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error()); $_SESSION['has_posted'] = 'yes'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if required fields aren't empty, process into database } else { echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if required fields were left empty, show an error dialog } }/* else { echo '<script>alert("Please follow the form to this page.");</script>'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if they weren't even referred from the form, show error dialog and redirect } // if isset post shout /* STARTING THE MAIN SCRIPT NOW */ // starting the table //displaying the shouts getShouts(); mysql_close($l); ?> Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/ Share on other sites More sharing options...
trq Posted August 30, 2010 Share Posted August 30, 2010 Header errors have nothing to do with where a file is included. You cannot however have any output sent to the browser prior to calling the header function. This for instance.... echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); will cause errors because echo sends data to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105057 Share on other sites More sharing options...
inkzoid Posted August 30, 2010 Author Share Posted August 30, 2010 Could you give me a hand here? Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105147 Share on other sites More sharing options...
trq Posted August 30, 2010 Share Posted August 30, 2010 What exactly are you doing and what is the exact error your getting? Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105150 Share on other sites More sharing options...
inkzoid Posted August 30, 2010 Author Share Posted August 30, 2010 I'm trying to take the comment box and put it at the bottom of my gallery page ( http://www.inkzoid.com/gallery.php ) where the old comment box that I'm currently using is. The error message I'm getting when I try to use the php include function to include the php script in my gallery.php page is a typical header location error. It says: Warning: include(/shoutbox/shout.php) [function.include]: failed to open stream: No such file or directory in D:\Hosting\5612165\html\gallery.php on line 190 Warning: include() [function.include]: Failed opening '/shoutbox/shout.php' for inclusion (include_path='.;C:\php5\pear') in D:\Hosting\5612165\html\gallery.php on line 190 I know this is coming up because the session_start(); function of my shoutbox.php file is not the very first line on my gallery page (the whole file is included near the bottom of gallery.php), but if I put the shoutbox.php file at the top of gallery.php using include, then the shoutbox will show up at the top of the page, which is not where I want it to show up. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105354 Share on other sites More sharing options...
PFMaBiSmAd Posted August 30, 2010 Share Posted August 30, 2010 Did you bother to read the error message? It has nothing to do with the session_start() nor is it even a header error - No such file or directory The path you are using is not valid. The leading slash / you are using refers to the root of the current hard disk. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105380 Share on other sites More sharing options...
fortnox007 Posted August 30, 2010 Share Posted August 30, 2010 Could you give me a hand here? Place header before the <html> tag But that has nothing to do with your initial question : ) When including files btw, make sure the path is correct. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105401 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 @PFMaBiSmAd - Thanks for pointing out my path error...it has been corrected. @fortnox007 - I apologize but I'm a beginner to PHP...did you mean I should cut the header line from my shout.php script and paste it before the html in my gallery.php file, or copy and paste it instead? I copied it and put it before the html in gallery.php and got a Firefox error (Firefox has detected that the server is redirecting the request for this address in a way that will never complete). This is what I currently have above the html tag on line 1 of gallery.php: <?php header("Location: http://www.inkzoid.com/gallery.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105424 Share on other sites More sharing options...
trq Posted August 31, 2010 Share Posted August 31, 2010 Now you are redirecting gallery to gallery, this causes an endless loop. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105425 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 Oh crap Alright I'll change it to link to shout.php and see if I can get a different result Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105426 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 Alright so the header location has been changed to shoutbox/shout.php in the gallery.php file and in the shout.php file the 2 references to header location are shoutbox/shout.php. I have the same error as before. I also go the same error when I changed them both to header location gallery.php . Obviously I am doing something wrong... Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105427 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 Ok I'm trying to go through in my head thinking what exactly I'm doing wrong here... My syntax for gallery.php line 1 is correct In shout.php the header location points to itself (shoutbox/shout.php) and there is no slash at the beginning this time, so the path is correct... I can get gallery.php to show the shoutbox only and not the rest of the gallery page, so I'm partway there... Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105432 Share on other sites More sharing options...
trq Posted August 31, 2010 Share Posted August 31, 2010 Post your current code and the exact error you are getting. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105433 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 Line 1 of gallery.php <?php header("Location: http://www.inkzoid.com/shoutbox/shout.php"); ?> Here's shoutbox/shout.php: <?php @session_start(); // calling session_start() the function which starts our authentication session // connecting to mysql server $l = mysql_connect ( "999.999.999.999" , "inkzoid" , "999" ) or die("Error connecting:<BR><BR>".mysql_error()); mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error()); // defining getShouts() which is our function that gets all of our shouts function getShouts() { echo '<div align="left"> <table width="800" bgcolor="#128911" border="0" cellspacing="0" cellpadding="0"> <tr> <td> '; $query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_array($query) ) { //print_r($row); $name = stripslashes($row['name']); $contact = stripslashes($row['contact']); $shout = stripslashes($row['shout']); if(empty($contact)) { echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>'; } else { echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>'; } // if empty contact } // while row mysqlfetcharray query echo '<br><br>'; echo ' </td> </tr> <tr> <td height="10"> </td> <form name="shout" method="post" action="shout.php"> <div align="center"> <input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br> <input name="contact" type="text" id="contact" value="http://" size="25"><br> <input name="message" type="text" id="message" value="Message" size="25"><br> <input name="shout" type="submit" id="shout" value="Shout!"> </div> </form> </td> </tr> </table> </div> '; } // function getshouts // our processing if control statement if ( isset ( $_POST['shout'] ) ) { $name = addslashes($_POST['name']); $contact = addslashes($_POST['contact']); $message = $_POST['message']; if ( ( isset($name) ) && ( isset($message) ) ) { // getting smilie list $smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error()); while($get = mysql_fetch_array ($smilies)) { $alt = $get['Alt']; $smilie = $get['URL']; $message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message); $themessage = addslashes($message); // replacing all smilies } mysql_query("INSERT INTO shouts (name, contact, shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error()); $_SESSION['has_posted'] = 'yes'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if required fields aren't empty, process into database } else { echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if required fields were left empty, show an error dialog } }/* else { echo '<script>alert("Please follow the form to this page.");</script>'; header("Location: http://www.inkzoid.com/shoutbox/shout.php"); // if they weren't even referred from the form, show error dialog and redirect } // if isset post shout /* STARTING THE MAIN SCRIPT NOW */ // starting the table //displaying the shouts getShouts(); mysql_close($l); ?> Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105436 Share on other sites More sharing options...
inkzoid Posted August 31, 2010 Author Share Posted August 31, 2010 Firefox says when I click on gallery.php: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. * This problem can sometimes be caused by disabling or refusing to accept cookies. Quote Link to comment https://forums.phpfreaks.com/topic/212046-trying-to-include-a-php-file/#findComment-1105437 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.