Solved

website not working, connecting to database

Posted on 2011-03-02
11
809 Views
Last Modified: 2012-05-11
Hi,

Just wondering if someone could point me in the right direction as to why my website is not connecting to the database.  

I have changed the config file to match the db name, password etc.  But the webiste is not connecting!!  Is there something else I need to change?

URL attached below.
URL.txt
0
Comment
Question by:wood1e
  • 6
  • 4
11 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
Turn on error checking by adding this to the  start of your script

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);

and see what messages you get. Alternatively check the error logs. Another alternative is to add a die clause to the mysql_ commands like so

mysql_connect(.......data.....) or die( "Error - " . mysql_error() );

0
 

Author Comment

by:wood1e
Comment Utility
I have added to the top of my settings.php file, FTP'd and refreshed but nothing happened?

And I think there die settings throughout the pages.
0
 
LVL 17

Expert Comment

by:psimation
Comment Utility
I cannot see any usefull erros from that URL.

Can you post your code snippets, then we could assist by giving you examples of making db errors verbose in order to debug.
0
 

Author Comment

by:wood1e
Comment Utility
Ok what code would you need I have attached the config.php without certain informaiton obviously. :)

<? 

   session_start();
   error_reporting(5);
   
   // TIME & DATE
   $today               = getdate(time());
   $date             = $today['weekday'].", ".$today['month']." ".$today['mday'];
   $date_database       = $today['year']."-".$today['mon']."-".$today['mday']." ".$today['hours'].":".$today['minutes'].":".$today['seconds'];
   
   $date_year           = $today['year'];
   $date_mon            = $today['mon']; if ($date_mon < 10) {$date_mon = "0$date_mon";}
   $date_mday           = $today['mday']; if ($date_mday < 10) {$date_mday = "0$date_mday";}
   
   $date_day            = $today['weekday'];
   $date_month          = $today['month'];
   $time             = time();
   
   $monthname           = Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
   $monthname2          = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
   $date_today          = $date_mday."-".$monthname2[$date_mon-1]."-".$date_year;
   $date_today_time     = $date_mday."-".$monthname2[$date_mon-1]."-".$date_year. " / " .$today['hours'].":".$today['minutes'].":".$today['seconds'];
   $date_name           = $date_mday." ".$date_month." ".$date_year;
   
   
   
   
   // DATABASE SETTING
   $db_host          = "mysql1.DB.net";
   $db_name          = "dbname";
   $db_username         = "username";
   $db_password         = "password";
   
   
   
   
   // EMAIL SETTING
   $smtp_server         = "smtp.synaxissolutions.co.uk";
   $smtp_username       = "info@synaxissolutions.co.uk";
   $smtp_password       = "password";
   $smtp_auth           = true;
   
   $email_from          = "info@mywesbite.co.uk";
   $email_from_name     = "mywebsite";
   $email_wordwrap         = 50;
   
   
   
   
   // ROWS SETTING
   $admin_rows          = 3;
   $delivery_charge_rows   = 9;
   $product_price_rows     = 7;
   
   

   
   // ADMIN EMAIL
   $admin_email         = "website<info@mywesbite.co.uk>";
   
   
   
   
   // DIRECTORY & URL SETTING
   $dir_base            = "$DOCUMENT_ROOT";
   $url_base            = "http://$HTTP_HOST";
   
   $dir_photo           = "$dir_base/photo";
   $url_photo           = "$url_base/photo";
   
   $dir_icon            = "$dir_base/icon";
   $url_icon            = "$url_base/icon";
   
   $dir_popup           = "$dir_base/popup";
   $url_popup           = "$url_base/popup";
   
   $dir_temp            = "$dir_base/temp";
   
   

   
   // PHP ERROR CONTROLL
   setCookie("warning", "");
   
   
   
   // Setting value for product brief info
   $cproduct_brief_info = "
   <table cellspacing='0' cellpadding='0' width='100%' border='0'>
      <tbody>
         <tr>
            <td align='center'><img height='61' alt='' src='/pictures/Image/lower_price.gif' width='64' border='0'/></td>
            <td width='10'>&nbsp;</td>
            <td valign='top'>
               <table cellspacing='1' cellpadding='1' border='0'>
                  <tbody>
                     <tr>
                        <td>
                           <table cellspacing='1' cellpadding='1' border='0' class='normal_12_black'>
                              <tbody>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                              </tbody>
                           </table>
                        </td>
                        <td width='5'>&nbsp;</td>
                        <td>
                           <table cellspacing='1' cellpadding='1' border='0' class='normal_12_black'>
                              <tbody>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                                 <tr>
                                    <td><img height='6' alt='' src='/pictures/Image/blue_square.gif' width='5' border='0'/>&nbsp;Text Here</td>
                                 </tr>
                              </tbody>
                           </table>
                        </td>
                     </tr>
                  </tbody>
               </table>
            </td>
         </tr>
      </tbody>
   </table>
   ";
   
   
   // PHP TO READ DATABASE
   $db_connect = mysql_connect($db_host, $db_username, $db_password);
   mysql_select_db($db_name, $db_connect) || die(mysql_error());
   
   // read email user/orders templates
   $tsql_query                   = "SELECT * FROM setup_email WHERE email_id = 1";
   $result                    = mysql_query($tsql_query) or die (mysql_error());
   $row                       = mysql_fetch_array($result);
   $email_customer_order            = $row[email_text];
   
   
   // read email user/recover password templates
   $tsql_query                   = "SELECT * FROM setup_email WHERE email_id = 2";
   $result                    = mysql_query($tsql_query) or die (mysql_error());
   $row                       = mysql_fetch_array($result);
   $email_customer_recover_password = $row[email_text];
   
   mysql_close($db_connect);
   
   
   
   
   // FORM DATA POST CONTROLL
   reset ($HTTP_POST_VARS);
   while (list ($key, $val) = each ($HTTP_POST_VARS)) {
       $HTTP_POST_VARS[$key] = stripslashes ($HTTP_POST_VARS[$key]);
       $HTTP_POST_VARS[$key] = str_replace  ("'", "''", $HTTP_POST_VARS[$key]);
       $HTTP_POST_VARS[$key] = str_replace  ("\"", "\\\"", $HTTP_POST_VARS[$key]);
       $HTTP_POST_VARS[$key] = str_replace  ("\\", "", $HTTP_POST_VARS[$key]);
   }
   extract ($HTTP_POST_VARS, EXTR_OVERWRITE, "wddx");
   reset ($HTTP_POST_VARS);
   
   
   
   
   // CACHE CONTROLL
   header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
   header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
   header ("Cache-Control: no-cache, must-revalidate");
   header ("Pragma: no-cache");
   
   

?>

Open in new window

0
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
Change

mysql_select_db($db_name, $db_connect) || die(mysql_error());

to

mysql_select_db($db_name, $db_connect) or die(mysql_error());


'or' in PHP and a logical OR || are not the same
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:wood1e
Comment Utility
I have change it.  Although there is no change. I presume you meant line 141 of code above?
0
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
OK - here is what I would change

Line 1: Use <?php instead of <? - most servers don't have SHORT_TAGS enabled

Line 29: Unless the MySQL database is hosted on another server elsewhere change this line to $db_host  = "localhost";

Line 66: $DOCUMENT_ROOT has not been defined. Stylistically is it considered bad form to use uppercase for user defined variables. Also you may actually mean $_SERVER['DOCUMENT_ROOT']   $dir_base = strip_tags( $_SERVER['DOCUMENT_ROOT'] );

Line 67: Similar to 66    $url_base  = strip_tags( "http://" . $_SERVER['HTTP_HOST'] );

Line 148: Should be   $email_customer_order  = $row['email_text'];

Line 155: Should be   $email_customer_recover_password = $row['email_text'];

This is obviously a very old script. $HTTP_POST_VARS was swicthed off years ago. Use $_POST instead



Try changing that lot and see how it works out




0
 

Author Comment

by:wood1e
Comment Utility
Sorry I do not understand the answers to line

66
67 or do you mean just copy the line you have writen?

What is the document root? If it is not document root?  Upper or lower case.

Everthing is within a folder called anglo.

It is a very old script, trying to get it working for someone who is not wanting to pay a huge amoutn for an ecommerce site.  plus I wanted to learn on a old site i thought should be working!! :)
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
Comment Utility
Lines 66 and 67 should be

$dir_base = strip_tags( $_SERVER['DOCUMENT_ROOT'] );
$url_base = strip_tags( "http://" . $_SERVER['HTTP_HOST'] );


"What is the document root? If it is not document root?  Upper or lower case."

The document root directory under which the current script is executing, as defined in the server's configuration file. See http://www.php.net/manual/en/reserved.variables.server.php (scroll down for more info)


"It is a very old script, trying to get it working for someone who is not wanting to pay a huge amoutn for an ecommerce site.  plus I wanted to learn on a old site i thought should be working!! :)"

This script is from PHP3 or possibly the early PHP4 era (HTTP_POST_VARS was deprecated in 2001 in PHP4.1) so that makes it more than 10 years old. Most of the features of those early versions were riddled with bad practices and security holes which is why they were changed or turned off or removed completely. Learning PHP on code this old is a waste of your time because no modern version of PHP will execute those scripts without alteration.

Your customer will find that on his next server upgrade, all this old code will simply stop working unless you go through it all and bring it up to date first.
0
 

Author Comment

by:wood1e
Comment Utility
That could be part of the reason the code is not working now?

As my servers were upgraded, and when thiking about it I noticed that an email came through saying something about php4/php5 that all websites in future should be coded php5 where possible!!

Ok I am not going to waste time on this, many thanks for your help.  The client will have to pay!! :)
0
 

Author Closing Comment

by:wood1e
Comment Utility
Many thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Are you using email marketing software? If not, you're missing out on effortless marketing and the reaching of desired conversion rates through email marketing software.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now