Jump to content

[SOLVED] php server configuration different from xampp ?


j33baS

Recommended Posts

Hi i have just tried to upload code onto a brand new web server, the code is an exact copy and the database is exactly the same too, all I changed was my config.php file where the username, databasename, host etc are stored.

 

The connection works as i dont get any error messages, but when queries which run perfect on my local xampp server dont work on the webserver ... for instance ....

 

<table width="600" border="0" cellpadding="0" cellspacing="0">

	  	<?php

	  	$titlequery = "SELECT * FROM entries
	  	ORDER BY dateposted DESC
	  	LIMIT 0, 5;";

	  	$titleresult = mysql_query($titlequery);

	  	while($row = mysql_fetch_array($titleresult)){

	  	echo "<tr><td><div align=\"left\">";


	  	//echo $row['subject'];
	  	echo "<li><a href='viewentry.php?id=" . $row['id'] . "'>" . $row	['subject'] . "</a></li>";

	  	echo "</td></tr>";
	  	      }
	  	    ?>
	  	</table>

 

will give me my lovely links to news stored in my DB, but on the webserver installation i get ....

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/timmycl/public_html/index.php on line 82

 

Like i said this is my first time trying to get a site working which was not local to my machine! any help would be greatly appreciated!

 

Thanks

Link to comment
Share on other sites

The problem is simply that you fail to check your queries return value prior to using any returned result. This is a common error, but one that is easily avoided using the proper syntx. eg;

 

<?php

  $sql = "YOUR QUERY";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      // now it is safe to use mysql_fetch_assoc
      while ($row = mysql_fetch_assoc($result)) {
        // diplsay data
      }
    } else {
      // no records found
    }
  } else {
    // query failed, handle error.
  }

?>

Link to comment
Share on other sites

<?php
require("header.php");
?>


<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="600"><table width="600" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="400" id="mainContent">
	<h2>Welcome</h2>

	<table width="600" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td width="170" height="20">
		<table width="170" border="0" cellspacing="0" cellpadding="0">
	        <tr>
	          <td><div align="center"><img src="images/wasps.gif"></div></td>
	        </tr>
	        <tr>
	          <td><div align="center"><img src="images/munster.gif"></div></td>
	        </tr>
	      </table> </td>
	    <td width="430">
	    
	      <p> </p>
	      </td>
	  </tr>
</table>

	<table width="600" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td><div align="center"><b>x x x</b> </div></td>
	  </tr>
	  <tr>


	  </tr>
</table>
<p>

          </td>
        </tr>
        <tr>
          <td><img src="images/news_banner.jpg"></td>
        </tr>
        <tr>
          <td><div align="center">

          <!-- this is code for the headlines -->
	  	<table width="600" border="0" cellpadding="0" cellspacing="0">

	  	<?php

	  	$titlequery = "SELECT * FROM entries
	  	ORDER BY dateposted DESC
	  	LIMIT 0, 5;";

	  	$titleresult = mysql_query($titlequery);

	  	while($row = mysql_fetch_array($titleresult)){

	  	echo "<tr><td><div align=\"left\">";


	  	//echo $row['subject'];
	  	echo "<li><a href='viewentry.php?id=" . $row['id'] . "'>" . $row	['subject'] . "</a></li>";

	  	echo "</td></tr>";
	  	      }
	  	    ?>
	  	</table>
<!-- end headline code -->

            </div></td>
        </tr>
      </table></td>
    <td width="200" bgcolor="#990000" id="adspace">
    <div align="center">
    <a href="hospitality.php"><img src="images/hospitalityad.jpg" width="185" height="450" border="0"></a>
    <p>
    <a href="ticket.php"><img src="images/ticket_ad.jpg" border="0"></a>
    </td>
  </tr>
</table>

<?php
require("footer.php");
?>

 

... thats the whole lot, and i know my connection to the DB is being set up fine cos  dont get any error messages back (its made in header.php).

 

Like i said iv got xampp installed and having been using it for developing, and just went to upload all the code to the web server i just bought so i was kinda hoping it would work the same !

 

Thanks

Link to comment
Share on other sites

yea sorry i copy n pasted the old file.

 

i put it in where ginger robot said, and i got the error:

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/timmycl/public_html/index.php on line 81

 

regardless of error handling, you cant think of any reason why 2 sets of identical code would perform differently on different servers which to me appear identical in setup!?

Link to comment
Share on other sites

At a guess I would say the problem is with your database. I would be tempted to say maybe differing MySQL versions but the query's so simple that's probably not the problem. The mysql_error() will reveal all though so could you please just post line 81 so we can fix your syntax error and find out what mysql_error() says.

Link to comment
Share on other sites

<?php

$titlequery = "SELECT * FROM entries
ORDER BY dateposted DESC
LIMIT 0, 5;";

$titleresult = mysql_query($titlequery); or die(mysql_error());   <---- [b]line 81[/b]
while($row = mysql_fetch_array($titleresult)){

echo "<tr><td><div align=\"left\">";


//echo $row['subject'];
echo "<li><a href='viewentry.php?id=" . $row['id'] . "'>" . $row ['subject'] . "</a></li>";

echo "</td></tr>";
}
?>

 

lol sorry dude thanks for trying to help im gettin so frustrated and getting myself all mixed up !

Link to comment
Share on other sites

ahh see! im retarded i could have been looking at that all night ...

 

ok it says no DB selected ....

 

so here is my header...

 

<?php
require("config.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
<script type="text/javascript" src="countdown.js" defer="defer"></script>
</head>

<body background="images/ed_tile.gif">
<div id="main" align="center">
  <table width="800" height="209" border="3" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
    <tr>
      <td height="209" bgcolor="#F4F4F4"><table width="800" height="165" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><div align="center"><img src="images/banner.jpg" width="800" height="100"></div></td>
          </tr>
          <tr>
            <td><div align="center"><font color="#FFFFFF" size="4" face="Verdana, Arial, Helvetica, sans-serif"><img src="images/nav.jpg" width="800" height="29" border="0" usemap="#Map2"></font></div>
             <map name="Map2">
		    <area shape="rect" coords="11,6,106,24" href="index.php">
		    <area shape="rect" coords="140,7,190,24" href="news.php">
		    <area shape="rect" coords="217,4,314,24" href="schedule.php">
		    <area shape="rect" coords="346,6,432,25" href="pictures.php">
		    <area shape="rect" coords="459,6,551,24" href="contacts.php">
		    <area shape="rect" coords="581,7,675,24" href="lastyear.php">
		    <area shape="rect" coords="698,6,786,24" href="sponsor.php">
  </map>
            </td>
          </tr>
          <tr>
            <td>





 

and here is my config.php

 

<?php

$dbhost = "localhost";  <-- this shud work right ?
$dbuser = "timmycl_eri";    <-- this is how the DB appears in phpMyadmin
$dbpassword = "my password";
$dbdatabase = "my username";

$config_sitename = "site name";
$config_author = "my name";
$config_basedir = "http://www.my domain.com/";

?>

Link to comment
Share on other sites

for the love of god i've just seen my own error... had the username and database variables mixed up...Once again i owe my life to you guys ! and sorry for wasting your time.

 

Thanks a million, only wish i could return the favor in some way but I doubt that will happen, cos i am stuuuuuuupid

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.