j33baS Posted January 19, 2008 Share Posted January 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/ Share on other sites More sharing options...
GingerRobot Posted January 19, 2008 Share Posted January 19, 2008 Whenever you are having mysql issues, add an or die statement to the query: $titleresult = mysql_query($titlequery) or die(mysql_error()); This will tell you the error mysql is giving. Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443783 Share on other sites More sharing options...
j33baS Posted January 19, 2008 Author Share Posted January 19, 2008 ok thanks, i just added that ... Parse error: syntax error, unexpected T_LOGICAL_OR in /home/timmycl/public_html/index.php on line 81 im really confused as to why it should be different ? Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443789 Share on other sites More sharing options...
trq Posted January 19, 2008 Share Posted January 19, 2008 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. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443811 Share on other sites More sharing options...
j33baS Posted January 19, 2008 Author Share Posted January 19, 2008 yea fair enough, but i'm still failing to see why code works on my local installation and doesnt on my websever, when they r both connecting to identical databases and are both running off php 5.2.5 ??? really confused ... Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443893 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Post the new code. Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443905 Share on other sites More sharing options...
j33baS Posted January 20, 2008 Author Share Posted January 20, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443915 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 I can't see an 'or die(mysql_error());' at all... Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443918 Share on other sites More sharing options...
j33baS Posted January 20, 2008 Author Share Posted January 20, 2008 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!? Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443923 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443924 Share on other sites More sharing options...
j33baS Posted January 20, 2008 Author Share Posted January 20, 2008 <?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 ! Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443927 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Ah well the syntax error comes from having a semicolon in-between 'mysql_query()' and 'or'. Remove it and you should be good to go with checking the SQL error. Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443932 Share on other sites More sharing options...
j33baS Posted January 20, 2008 Author Share Posted January 20, 2008 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/"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443937 Share on other sites More sharing options...
j33baS Posted January 20, 2008 Author Share Posted January 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443943 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 It happens to us all at some point in one way or another... Quote Link to comment https://forums.phpfreaks.com/topic/86835-solved-php-server-configuration-different-from-xampp/#findComment-443946 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.