Page 1 of 1

can't connect to database error

Posted: Tue Jul 14, 2015 7:33 am
by smithedison
This is strange I return the first name and surname from a table. If I echo the 2 fields out I get the correct result. If however I try to use it in a html line I get an error Can't connect to database even though I have already done it and got the result set back.

I use a trigger error that sends me to an error page with this error, but it works fine if I don't try to use the result set in my page.

If I comment out the trigger error and use a standard connection it ALL works FINE.

Code: Select all

?  
    $qUserData = GetUser($ID); 
    $rs = mysql_fetch_array($qUserData); 
    //echo $rs['UserF'] . " " . $rs['UserS']; 
    //exit; 
?> 
    <h2>Edit User Shelves for: <?=$rs['UserF']?></h2><br> 

This works if I remove the commented out echo and exit. 

============= 


  if(!$link = @mysql_connect($host, $user, $pass)) 
    trigger_error('Can\'t connect to server: ('. $db . ')', E_USER_ERROR); 

  if(!$database = @mysql_select_db($data, $link)) 
    trigger_error('Can\'t select database on: (' . $db . ')', E_USER_ERROR); 
     
   
    //$link = @mysql_connect($host, $user, $pass); 
    //$database = @mysql_select_db($data, $link); 


If I remove the trigger errors and replace it with the normal connection it all works perfectly. The trigger error should be happening when I connect to the database not when I try to use 

<h2>Edit User Shelves for: <?=$rs['UserF']?></h2><br> 

This is strange...

Re: can't connect to database error

Posted: Fri Jul 24, 2015 5:57 pm
by Pazuzu156
I don't see any connection in the first example, I don't know how that's laid out, but it looks like there's no connection.

In the second example, the reason the trigger_error may/may not get called how you want is because in your calls to mysql_connect, you're using the @ suppressor.

This suppresses errors, so that could likely be the cause, remove them.