Is this a PHP 5 issue

Discussion in 'PHP' started by Deepprogrammer, Nov 1, 2012.

  1. #1
    OK, I've been using a CMS built by a friend of mine who is an absolute genius. I've been using it for years with no problem. But now, nothing works, not even the query checks. So, I have the following code after the login status:


    $mysql = mysql_connect($host, $user, $pass); if(!$mysql) { echo 'Cannot connect to database. Please try again or email sean@caillouett.com'; exit; } // select the appropriate database $mysql = mysql_select_db($db); if(!$mysql) { echo 'Cannot select database. Please try again or email sean@hostname.com'; exit; } // query the database to see if there is a record which matches $query = "select * from login where username = '$username' and psswd = '$psswd'"; $result = mysql_query( $query ); if(!$result) { echo 'Cannot run query.'; exit; }
    When I try to login, none of the checks work . . . nothing happens at all. Is this a PHP4 vs. PHP5 issue. Can anyone give me some insight.

    thanks so much!
     
    Deepprogrammer, Nov 1, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    try error_reporting(E_ALL) on top of your scripting code (after <?) and see if you get any errors.
     
    EricBruggema, Nov 2, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    Add the code in red. Let us know what you see. You should see
    1
    2
    3
    4
    5
    6
    got this far
    
    $mysql = mysql_connect($host, $user, $pass);
    [COLOR=#ff0000]echo '1<br />';[/COLOR]
         if(!$mysql)     {       
      echo 'Cannot connect to database. Please try again or email sean@caillouett.com';       exit;     
    }     
    // select the appropriate database     
    [COLOR=#ff0000]echo '2[/COLOR][COLOR=#ff0000]<br />[/COLOR][COLOR=#ff0000]';[/COLOR]
    $mysql = mysql_select_db($db);     
    [COLOR=#ff0000]echo '3[/COLOR][COLOR=#ff0000]<br />[/COLOR][COLOR=#ff0000]';[/COLOR]
    if(!$mysql)     {
      echo 'Cannot select database. Please try again or email sean@hostname.com';       exit;     
    }      
    // query the database to see if there is a record which matches     
    [COLOR=#ff0000]echo '4[/COLOR][COLOR=#ff0000]<br />[/COLOR][COLOR=#ff0000]';[/COLOR]
    $query = "select * from login where               username = '$username' and               psswd = '$psswd'";
    [COLOR=#ff0000]echo '5[/COLOR][COLOR=#ff0000]<br />[/COLOR][COLOR=#ff0000]';[/COLOR]
    $result = mysql_query( $query );
    [COLOR=#ff0000]echo '6[/COLOR][COLOR=#ff0000]<br />[/COLOR][COLOR=#ff0000]';[/COLOR]
          if(!$result)     {
      echo 'Cannot run query.';       
      exit;     
    }
    [COLOR=#ff0000]echo 'got this far';
    exit;[/COLOR]
    
    Code (markup):
     
    Rukbat, Nov 2, 2012 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Would help if the formatting wasn't mangled -- hoping the forums did that and not you since if it's all compressed to one line, everything after the first // would be ignored.

    NOT that the code makes any sense as the call to mysql_select_db would erase the actual database handler. This line:

    $mysql = mysql_select_db($db);

    means you could never tell it which connection to close or target the connection -- the same variable should NEVER be used for mysql_select_db as is used for mysql_connect.

    dunno if I'd call that mess 'genius'... would probably depend on how long ago it was written.

    But as others have suggested, making it report what errors are happening or giving us a better idea HOW it's failing would let us dial in the answer.
     
    deathshadow, Nov 2, 2012 IP