ryanstrong Posted March 4, 2007 Share Posted March 4, 2007 I have the below code uploaded on yahoo's web hosting service. PHP is installed - phpinfo() runs and shows the details of the installation. The php code inserted into html below does not run however, and when I view source, I can see the php code. I'm very new to php and am struggling with this - help is very very appreciated. - Clueless. ??? <html> <head> <?php session_start(); ?> <title>hello</title> </head> <body> <?php echo ("test"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/ Share on other sites More sharing options...
wildteen88 Posted March 5, 2007 Share Posted March 5, 2007 Make sure the file extension for the file is .php and not .php.txt or .php.html Also your PHP code will error out. You cannot start session after output has been made to the browser. I am referring to this section of code: <html> <head> <?php session_start(); ?> ... Place session_start(); before any output, usually at the tp of the script, example: <?php // start the session before any output. // Anything that is being echo'd or placed out side //of the PHP tags is classed as output. session_start(); ?> <html> <head> <title>hello</title> </head> <body> <?php echo ("test"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/#findComment-200152 Share on other sites More sharing options...
ryanstrong Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks for your reply! The file extension is .html - I thought that I could embed php code into an html page - is this not true? If it is not true, is there a way to call a php script from an html page without using a form or requiring the user to click a button? - A bit less clueless, but still clueless. ??? Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/#findComment-203045 Share on other sites More sharing options...
wildteen88 Posted March 9, 2007 Share Posted March 9, 2007 Save as .php instead. PHP files can contain everything a .html file can have. Accept a .php file allows you to include PHP code within it. Just make sure all PHP code is within the PHP code blocks (<?php ?>). YOu can go in and out of the PHP code blocks as many times as you like there is no limitation. You cannot use PHP like you can with Javascript. They are completely different. Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/#findComment-203676 Share on other sites More sharing options...
ryanstrong Posted March 15, 2007 Author Share Posted March 15, 2007 So I got some output thanks to your help. Now I'm trying to go a few steps further and am having problems...I want to connect to a mysql db I created but my file does not show any output...not even the error outputs...so I'd think maybe my query isn't returning results or I'm not outputting correctly? But it is a very simple query and I took the code from a book just to get familiar with it. Here is my code (in file test.php). The include file is the standard setup of host, username & pw...except yahoo requires you to use 'mysql' instead of 'localhost.' One additional piece of info...the 2nd data field in the 'recipes' table is the name of a recipe. I only have one record in the database and this field does contain data. Whats also odd is that the echo line at the top of the page (hello world) does not output when I add all the mysql related code. Wondering why this is... Help! <html> <head> <?php session_start(); ?> <title>test</title> </head> <body> <?php echo ("hello world"); ?> <?php //Include Login Information include('db_login.php'); //Connect $connection = mysql_connect($db_host, $db_username, $db_password); if(!$connection) { die("Could not connect to the database: <br />". mysql(error()); } //Select the Database $db_select = mysql_select_db($db_database); if(!$db_select) { die("Could not select the databse: <br />". mysql(error()); } //Assign the Query $query = "SELECT * FROM 'recipes'"; //Execute the Query $result = mysql_query( $query ); if(!$result) { die("Could not query the database: <br />". mysql_error()); } //Fetch & Display the Results while($result_row = mysql_fetch_row($result)) { echo $result_row[2] '<br />'; } //Close the connection mysql_close($connection); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/#findComment-207650 Share on other sites More sharing options...
ryanstrong Posted March 15, 2007 Author Share Posted March 15, 2007 Note, I did move the php session code before the html tags begin as per your previous post. But my last post still remains true regardless. Just an FYI. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41154-yahoo-web-hosting-php-execution-issues/#findComment-207677 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.