gw32 Posted April 29, 2011 Share Posted April 29, 2011 This doesn't work inside html. <tr valign="top"> <td height="22" align="right" valign="middle"><!-- <img src="images/bult-gamblingtemplatesdotnet.jpg" width="11" height="11"> --></td> <td height="22" valign="middle"><class="navbar3"> <?php include("config.php"); $result = mysql_query("SELECT name, lic_num, purpose FROM charity where sysdate() between start_date and end_date"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { print "<b>Charity: </b>".$row{'name'}."<br><b>License #: </b>".$row{'lic_num'}."<br><b>Purpose: </b>".$row{'purpose'}."<p>"; } mysql_close($dbh); ?></td> This is the output on the website. Charity: ".$row{'name'}." License #: ".$row{'lic_num'}." Purpose: ".$row{'purpose'}." "; } mysql_close($dbh); ?> When I do this <tr valign="top"> <td height="22" align="right" valign="middle"><!-- <img src="images/bult-gamblingtemplatesdotnet.jpg" width="11" height="11"> --></td> <td height="22" valign="middle"><class="navbar3"><?php include("test.php"); ?></td> </tr> I get this Can someone please point me in the correct direction? Also if I run the code as a stand alone it works perfectly. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/ Share on other sites More sharing options...
requinix Posted April 29, 2011 Share Posted April 29, 2011 Are you putting that code in a .php file and using include() or require() it? If it's .htm(l) or you're using file_get_contents() or similar then it might not work. Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208354 Share on other sites More sharing options...
gw32 Posted April 29, 2011 Author Share Posted April 29, 2011 It's in a .php file and I'm using include Here is the test.php file; <?php include("config.php"); $result = mysql_query("SELECT name, lic_num, purpose FROM charity where sysdate() between start_date and end_date"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { print "<b>Charity: </b>".$row{'name'}."<br><b>License #: </b>".$row{'lic_num'}."<br><b>Purpose: </b>".$row{'purpose'}."<p>"; } mysql_close($dbh); ?> Where config.php is the database connect info. Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208357 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 It's in a .php file and I'm using include Where are you using the include? All PHP code must be within a .php file. PHP code will not work within any other file type (unless the server is configured to do so). Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208363 Share on other sites More sharing options...
Pikachu2000 Posted April 29, 2011 Share Posted April 29, 2011 I'm thinking that the query is returning an empty result set. Do you get any results returned if you paste the query "SELECT name, lic_num, purpose FROM charity where sysdate() between start_date and end_date" in to phpMyAdmin (or whatever you prefer to use) and execute it? From looking at it, it seems like it should read more like: SELECT name, lic_num, purpose FROM charity where start_date < NOW() AND end_date > NOW() Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208375 Share on other sites More sharing options...
gw32 Posted April 29, 2011 Author Share Posted April 29, 2011 In my HTML code I am using it like this: <tr valign="top"> <td height="22" align="right" valign="middle"><!-- <img src="images/bult-gamblingtemplatesdotnet.jpg" width="11" height="11"> --></td> <td height="22" valign="middle"><class="navbar3"><?php include("test.php"); ?></td> </tr> Here is the webiste as it sits using the above: http://dswdesigns.net/pp4c/index.html Here is the stand alone code of test.php and it works: http://dswdesigns.net/pp4c/test.php Thanks Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208388 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 You cannot place php code within a .html file. That is why it is not working. Rename index.html to index.php and the PHP code will be parsed. Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208390 Share on other sites More sharing options...
gw32 Posted April 29, 2011 Author Share Posted April 29, 2011 THANKS That was the simplest answer and yet I was so far off it wasn't funny. THANKS Quote Link to comment https://forums.phpfreaks.com/topic/235120-php-code-in-html/#findComment-1208394 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.