Jump to content

Yahoo Web Hosting - PHP execution issues


Recommended Posts

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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>   

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.