ChaosXero Posted August 10, 2006 Share Posted August 10, 2006 I have a php script inside of an HTML document (index.php for my site) and after the PHP executes correctly it stops processing the page. It just stops everything. Even echoing the rest of the content does no good. I can post the code if necessary but has anyone had a similar problem or no of a solution? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 10, 2006 Share Posted August 10, 2006 yea post the code. We need to see it. Also what did you name this piece of code php or html? Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 10, 2006 Author Share Posted August 10, 2006 [code]<?PHP define("host", define("UNAME", define("pword", function print_news() { mysql_connect(host,UNAME,pword) or die(mysql_error()); mysql_select_db(); $sql = "SELECT * FROM `news` "; $result = mysql_query($sql) or die(mysql_error()); while($res = mysql_fetch_array($result) or die(mysql_error())){ echo "<table border=\"1\">"; echo "<tr><td>".$res['user']."</td><td>".$res['title']."</td><td>".$res['date']."</td></tr>"; echo "<tr><td colspan=\"3\">".$res['detail']."</td></tr>"; echo "</table>"; echo "<hr />"; } }?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><META NAME="DESCRIPTION" CONTENT="Normal Public Library Teen Advisory Council Book Discussion Group"><META NAME="KEYWORDS" CONTENT="books,book,discussion,teens,reading,writing,normal,public,library,"><title>Teen Advisory Home</title><link href="styles.css" rel="stylesheet" type="text/css"></head><body><div id="header"><p>Home | About | Meetings | Books | Links </p></div><div id="container"> <div id="content"> <p>You've reached the official home of the Normal Public Library's Teen Advisory Council. The groups main goal is to bring in teens who share common ground in the love of books, reading, writing and just having fun. For more info about the group check the 'about' page.</p> <hr /> <p><strong>News:</strong></p> <? print_news(); ?> </div></div><div id="footer">Page Created and Maintained By: Dave Lyon | Content and Design ©2006 Dave Lyon<br /> Hosted By: <a href="http://tialys.net">Tialys.net</a></div><div class="ad_nugget"><script type="text/javascript"><!--google_ad_client = google_ad_width = 120;google_ad_height = 240;google_ad_format = "120x240_as";google_ad_type = "text";google_ad_channel ="6524514903";google_color_border = "000000";google_color_bg = "990000";google_color_link = "FFFFFF";google_color_text = "FFFFFF";google_color_url = "000000";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div></body></html>[/code]everything up to the print_news() function displays correctly. After the function nothing shows up. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted August 10, 2006 Share Posted August 10, 2006 Is the like or die(mysql_error()) in the while loop necessary?If it's just stopping then the die() seems to be getting triggered. Though it might not be display the error message because the function might not be returning the value of it?? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 10, 2006 Share Posted August 10, 2006 Ok I don't know if you just changed the [code=php:0]define[/code] before posting it here but you need to do something like this [code=php:0]define("host", "yourhostname");[/code] now in your function do something like this.[code=php:0]function whatever() { $result = "This is something simple"; return $result;}$whatever = whatever();echo "$whatever";[/code]Not sure if this will solve your problem or not but give it a shot. Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 10, 2006 Author Share Posted August 10, 2006 I removed part of the define because it had my database info in it. Not sure what you meant by your example. Can you explain more based on my code? Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 11, 2006 Author Share Posted August 11, 2006 Bump... I've tried about everything and this still wont work... Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 11, 2006 Share Posted August 11, 2006 You are outputting HTML to the page before you even put the <HTML> tag. Move your PHP down to after the <BODY> tag so that you have valid HTML. This is most likely your error. Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 11, 2006 Author Share Posted August 11, 2006 The PHP used to be where that function call is and still caused the same exact error. I was hoping making it a function as such would fix it but no luck. Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 11, 2006 Share Posted August 11, 2006 Ah, I didn't read your code close enough to realize you were just defining a function up there... Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 11, 2006 Author Share Posted August 11, 2006 Free cookies and cupcakes if you solve this! I'm on like hour 3 here... Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 11, 2006 Share Posted August 11, 2006 what I meant by this post is you need to [code=php:0]return[/code] the desired result, the mysql_fetch_assoc or array. What I would do is this[code]<?phpdefine("host", "yourhost"); define("UNAME", "whatever");define("pword", "password"); function print_news() { mysql_connect(host,UNAME,pword) or die(mysql_error()); mysql_select_db(); $sql = "SELECT * FROM `news` "; $result = mysql_query($sql) or die(mysql_error()); while($res = mysql_fetch_assoc($result)){ $table = '<table border="1"> <tr> <td>' . $res['user'] . '</td> <td>' . $res['title'] . '</td><td>' . $res['date'] . '</td> </tr> <tr> <td colspan="3">' . $res['detail'] . '</td> </tr> </table>'; } return $table;}?>[/code]What this does is [code=php:0]return[/code] the variable $table. Now I would do something like this (where ever you want the table to be located in your html.[code=php:0]<?php$table = print_news();echo "$table";?>[/code]This will echo the returned varable from the function. I also recomend reading up on [url=http://us3.php.net/manual/en/language.functions.php]user defined functions[/url] and maybe [url=http://us3.php.net/manual/en/function.return.php]return[/url].Hope this helps,Tom Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 11, 2006 Author Share Posted August 11, 2006 Fixed! Turned out to be the 'or die' in the while loop. Thanks for all the suggestions everyone! 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.