PHP - SQL problem
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: PHP - SQL problem

  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422

    PHP - SQL problem

    I have been working on a website recently that needs to contain databases with things like emails (used as user name), passwords, and other information on the user. The problem I have been having is accessing the database using PHP. When I view this file in my browser, it only shows "connecting..." and doesn't continue with anything. I called the tech support, and that is the information they said to use, but its not working. I figured even if the information wasn't correct, it should go to the IF statement that displays an error, but that doesn't happen. Here is code that I have attempted to use to connect to the database. The domain is registered with Register.com if that helps. As you can tell, I am very new to PHP and SQL, so any help would be greatly appreciated.
    Code:
    <?php
    /* Program: mysql_up.php
     * Desc:    Connects to MySQL Server and 
     *          outputs settings.
     */
     echo "<html>
           <head><title>Test MySQL</title></head>
           <body>";
     $host="sql5c6a.megasqlservers.com";
     $user="dbm.restoretraditionalamerica.com";
     $password="*";
    echo "connecting...";
     $cxn = mysqli_connect($host,$user,$password);
    echo "connected";
     $sql="SHOW STATUS";
     $result = mysqli_query($cxn,$sql);
     if($result == false)
     {
        echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
     }
     else
     {
       /* Table that displays the results */
       echo "<table border='1'>
             <tr><th>Variable_name</th>
                 <th>Value</th></tr>";
       for($i = 0; $i < mysqli_num_rows($result); $i++) 
       {
         echo "<tr>";
         $row_array = mysqli_fetch_row($result);
          for($j = 0;$j < mysqli_num_fields($result);$j++) 
          {
             echo "<td>".$row_array[$j]."</td>\n";
          }
       }
       echo "</table>";
     }
    ?>
    </body></html>

  2. #2
    try with a simple script like this to see if it connects ok ->

    Code:
    // Connect to database.
    @mysql_connect("localhost", "loginname", "password") or die('<font face="helvetica">At this time we are unable to connect to the Database.<br><br>The most likely cause is a problem with the server hosting the database.<br><br>Please try again later as these problems tend to be transient.<br><br>We apologise for the inconvenience.</font>');
    
    @mysql_select_db("databasename") or die("Unable to select db");
    If this works with your info, maybe there's a typo somewhere in the other script?

    In this script too, "localhost" may need to be changed to the address of your ISP's server.

    Cheers,
    Niggles

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422
    I attempted to use localhost and the host i previously posted, both of which returned the answer: At this time we are unable to connect to the Database....

  4. #4
    Senior Member
    Join Date
    Feb 2003
    Location
    Memphis, TN
    Posts
    3,747
    Have you verified username, host information, password etc etc?

    your PHP connect to the MySQL database isn't working.

    Also you have an error in your connection string.

    $cxn = mysqli_connect

    should be
    $cxn = mysql_connect
    =

  5. #5
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    That mysqli statement is correct if the MySQL is version 4.1 or above.

    http://nl.php.net/manual/en/ref.mysqli.php

    There is a slight flaw in the code though. The code doesn't check if the connection actually succeeded.

    Add this and it may give you a clue why it's failing:
    Code:
    if (!$cxn) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  6. #6
    Senior Member
    Join Date
    Feb 2003
    Location
    Memphis, TN
    Posts
    3,747
    Ahh...shows you how adapt I am at programming...only do it when I have to..lol
    =

  7. #7
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Doesn't matter, I had to look up mysqli_ myself, I'm also used to seeing mysql_
    This shows you how long it's been since I played with the stuff

    It seems you can use mysql_ but the mysqli_ lets you make use of the features found in 4.1.0 and higher.
    Last edited by SirDice; December 14th, 2007 at 08:16 PM.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  8. #8
    Junior Member
    Join Date
    Nov 2007
    Location
    Seattle, WA
    Posts
    13
    Don't suppress your error messages in your test scripts. That's kind of counter-productive, no?

    My thoughts.

  9. #9
    Senior Member
    Join Date
    Oct 2003
    Location
    MA
    Posts
    1,053
    You have to isolate your problem so id comment out a bunch of code and see if it gets that far

  10. #10
    Senior Member
    Join Date
    Apr 2005
    Location
    USA
    Posts
    422
    The problem is it gets to line
    echo "connecting...";and is fine, but it seems to stop on the next line.

    I don't really know what you'd want me to comment out, because I know where its hanging, I just don't know what to do about it.

Similar Threads

  1. Shoestring SQL Injection Prevention
    By catch in forum The Security Tutorials Forum
    Replies: 27
    Last Post: August 9th, 2006, 08:01 AM
  2. Apache, PHP, MySQL with basic security settings.
    By nightcat in forum The Security Tutorials Forum
    Replies: 9
    Last Post: May 28th, 2005, 02:47 AM
  3. Installing Apache and PHP on Linux
    By HDD in forum Other Tutorials Forum
    Replies: 2
    Last Post: February 1st, 2004, 07:05 PM
  4. Student Suspended Over Suspected Use of PHP
    By mantra in forum AntiOnline's General Chit Chat
    Replies: 6
    Last Post: January 6th, 2003, 08:18 AM
  5. PHP SQL username encrypted
    By yuna_admirer in forum Programming Security
    Replies: 4
    Last Post: December 14th, 2002, 02:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides