Jump to content

Recommended Posts

I am creating a news updates thing for my website and i have managed to get it working on my home PC (im using XAMPP) but when i upload to my webhost it doesnt appear to work.

I am wondering if it is just my host or whether i have done something wrong and by chance it works on my home PC.

 

Here is my code:

<?php
include("includes.php");

doConnect();

$get_news = "SELECT title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC";

$result= mysqli_query($mysqli, $get_news)
	or die(mysqli_error($mysqli));

while ($row = mysqli_fetch_array($result)) {
echo '<strong>'. $row['title'] .' </strong><br>'. $row['text'] .'<br>'. $row['datetime'] .'<br><br>';}


?>

 

My includes file is:

<?php

function doConnect() {
	global $mysqli;

	//connect to server and select database
	$mysqli = mysqli_connect("localhost", "user", "password", "dbname");

	//if connection fails, stop script execution
	if (mysqli_connect_errno()) {
		printf("Connection failed: %s\n", mysqli_connect_error());
		exit();
	}
}
?>

 

I think im right in saying it connects properly because i do not see an error.

 

what i get is:

'. $row['title'] .'
'. $row['text'] .'
'. $row['datetime'] .'

';} ?> 

 

Im new to PHP (incase you hadnt guessed!) so not really sure whats happening.

On my home PC i have PHP Version 5.3.1 and on my webhost its 5.2.14. Home PC mySQL version 5.1.41 and on webhost its 5.0.91-community. Could this be the reason?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/224435-is-it-me-or-my-host/
Share on other sites

Wow quick reply. Thanks. Sorry forgot to mention this is in a .html file. I've included PHP in a HTML file before but could this be the reason? That would be the only thing thats changed from my local setup. That didnt cross my mind! changing to .php appears to work.

 

thanks very much

Link to comment
https://forums.phpfreaks.com/topic/224435-is-it-me-or-my-host/#findComment-1159389
Share on other sites

this is what i use in the top of .htaccess file to cause HTML, .htm and .shtml files to be parsed as PHP:

 

AddType application/x-httpd-php .html .htm .shtml

 

I have also seen variations on this, most often specifying php4 or php5 as follows:

 

AddType application/x-httpd-php5 .html .htm .shtml

Link to comment
https://forums.phpfreaks.com/topic/224435-is-it-me-or-my-host/#findComment-1159396
Share on other sites

Webhost Freaks - owned by PHPFreaks.com can assist you if needed: http://www.WebHostFreaks.com - all hosting sales go in direct support of PHPFreaks and our continued operation of this site.  We can parse .html files as PHP as well.

 

Thanks and Good Luck on your coding adventures.

 

Link to comment
https://forums.phpfreaks.com/topic/224435-is-it-me-or-my-host/#findComment-1159831
Share on other sites

Thanks for all your help guys. Much appreciated. Got my host to move me to a different server and now all is well and i have a site functioning as i want....for now!

 

I may well be back soon asking more questions, but will definately stick around reading other topics etc to gain more knowledge.

Link to comment
https://forums.phpfreaks.com/topic/224435-is-it-me-or-my-host/#findComment-1159837
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.