Website link in php block

I can't seem to get a website link to display on a profile page without generating error messages.  I used the code pasted below in a php block - modified a bit from something okweb posted, and it does work - i.e. it makes a working link on the profile page, but it generates the following errors:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'caltrade'@'localhost' (using password: NO) in /var/www/vhosts/CALTRADE.com/httpdocs/community/inc/classes/BxDolDb.php on line 508

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /var/www/vhosts/CALTRADE.com/httpdocs/community/inc/classes/BxDolDb.php on line 508

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/CALTRADE.com/httpdocs/community/inc/classes/BxDolDb.php:508) in /var/www/vhosts/CALTRADE.com/httpdocs/community/inc/design.inc.php on line 133

Strange thing is, I did this late in the evening and it worked fine - I checked on several profiles and it was working - but the next morning those errors appeared, and they have been there ever since when I move that block back.   Can anyone figure out what is going on?  The code I used is below if any gurus could take a look.

Rob

$profileID = getID( $_REQUEST['ID'] );

$my_dbHost="localhost";
$my_dbLogin="caltrade";
$my_dbPass="password7";
$my_db="caltrade7";

$connection=mysql_connect("$my_dbHost","$my_dbLogin","$my_dbPass") or die("Couldn't connect to the server.");

$db=mysql_select_db("$my_db", $connection) or die("Couldn't select a database.");

$sql="SELECT * FROM Profiles WHERE ID='$profileID'";

$sql_result=mysql_query($sql,$connection) or die("Couldn't execute query!");
$res=mysql_fetch_array($sql_result);


$Website=$res["Website"];


echo "<div class=\"boxContent\">";
echo "<table class=\"profile_info_block\" cellspacing=0 cellpadding=1>";


if( strlen($Website) > 0 )
{
echo "<tr><td class=\"profile_info_label\"><br />Link:    </td>
<td class=\"profile_info_value\" ><br />
<a href=\"http://$Website\" target=\"_blank\"><b>$Website</b></a>
</td></tr>";
}


if(strlen($Website) < 1)
{
echo "<tr><td class=\"profile_info_label\"></td><td class=\"profile_info_value\" ><b>No website link yet</b></td></tr>";
}

echo "</table>";
echo "</div>";

mysql_close($connection);

Quote · 16 Dec 2009

Hello!

This message "Access denied for user 'caltrade'@'localhost'" is interesting. May be something was made with DB user in this time. Check his privileges in Cpanel.

Regard

Quote · 16 Dec 2009

Make sure your DB still has you as a user, in cpanel.... or whatever you use.   I've had similar problems in the past when doing things like backing up and restoring a DB... etc.  For some strange reason, the DB users/pwds sometimes get wiped out.

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 16 Dec 2009

Nah, darn, I had already changed that password a few times but it didn't affect anything.   From these answers though, it occurred to me that maybe it had to be the same database user/password  I had used in the site install - but when I changed it that had no effect either.  Again, it does work - the link is there, but so are those horrible error messages at the top of the page.

Any other ideas?   Leonid - could there be something in cache doing this?  I have all my cache settings off and was wondering if something on the chron needs to come around.  I don't want to leave this on my live site, so when I test I put it there and remove quickly.   Has anyone else gotten a website link to work in a php block?

Rob

Quote · 16 Dec 2009

New code, work fine for me

global $p_arr;
$Memb = (int)$p_arr[ID];

$arr = db_arr("SELECT `Website` FROM `Profiles` WHERE `ID` = $Memb");
$website = $arr[Website];

echo "
<table class=form_advanced_table cellspacing=0 cellpadding=0>
";

if(strlen($website) > 1)
{
echo "
<tr>
<td class=caption>My website:</td>
<td class=value>
<a href=http://$website target=_blank><b>$website</b></a>
</td></tr>
";
}

if(strlen($website) < 1)
{
echo "
<tr>
<td class=caption></td>
<td class=value>
<b>No website link yet</b>
</td></tr>
";
}

echo "
</table>
";

Quote · 16 Dec 2009

BINGO!  Worked like a charm Ottar!  No password needed with this approach?  Here is a link that shows it working:

http://www.caltrade.com/community/Ozalomiy

Good job!

Rob

Quote · 16 Dec 2009

Again, this works great, but one thing that would be nice if the block just didn't appear at all if there was no website.  With other blocks, if they have no profile fields, they just don't get displayed, but with this one the block gets displayed with the words "no website link yet".  Not horrible, but it would be a nice fix to have the block be suppressed if the link wasn't there - if this is possible.

Rob

Quote · 17 Dec 2009

Yes it is possible. but you will have to change your code. The trick is not to output anything if there is no data. So the start and end of your table will have to be moved.

Try this,


global $p_arr;
$Memb = (int)$p_arr[ID];

$arr = db_arr("SELECT `Website` FROM `Profiles` WHERE `ID` = $Memb");
$website = $arr[Website];



if(strlen($website) > 1)
{

echo "
<table class=form_advanced_table cellspacing=0 cellpadding=0>
<tr>
<td class=caption>My website:</td>
<td class=value>
<a href=http://$website target=_blank><b>$website</b></a>

</td></tr>
</table>
";
}

https://www.deanbassett.com
Quote · 17 Dec 2009
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.