Hello,
I'm try to create a UDT that will add rows to a table I defined. Here is the code I'm using but I'm getting some errors. The code works fine outside CMSMS. What did I miss? Thanks
PHP Warning: mysql_real_escape_string(): Can't connect to MySQL server on 'localhost' (10061) in E:\hshome\xxxxxxxxxxxxxxx\lib\adodb_lite\adodbSQL_drivers\mysql\mysql_driver.inc on line 174
$username="user";
$password="password";
$database="db";
$myserver="server";
mysql_connect($myserver,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO tblVisits(url,realip,longip) VALUES ('".$_SESSION['url']."','".$_SERVER['REMOTE_ADDR']."','".gethostbyaddr($_SERVER['REMOTE_ADDR'])."')";
mysql_query($query);
mysql_close();
User Defined Tags
Re: User Defined Tags
Is part of this the UDT you are trying to make?
If not can you paste your code?
If not can you paste your code?
Re: User Defined Tags
This is the full code. Nothing is displayed to the user, it's just for tracking.
Re: User Defined Tags
How are you putting it in the edit content box for UDT?
You may need to use the {literal}your code {/literal} tags and put it in the Source button window.
You may need to use the {literal}your code {/literal} tags and put it in the Source button window.
- Elijah Lofgren
- Power Poster
- Posts: 811
- Joined: Mon Apr 24, 2006 1:01 am
- Location: Deatsville, AL
Re: User Defined Tags
It seems like maybe your UDT is knocking off CMSMS's DB connection.
Try this code, it will use CMSMS's DB connection:
Or maybe just remove this line from your code:
Oh, and from the looks of the code you may be interested in my VisitorStats module: http://dev.cmsmadesimple.org/projects/visitorstats 
Hope this helps,
Elijah
Try this code, it will use CMSMS's DB connection:
Code: Select all
global $gCms;
$db = &$gCms->db;
// $_SESSION['url'] = 'test'; // Commented out, only used for my testing. I assume you assign a value to it elsewhere
$query = 'INSERT INTO tblVisits (url,realip,longip) VALUES (?,?,?)';
$db->Execute(
$query,
array(
$_SESSION['url'],
$_SERVER['REMOTE_ADDR'],
gethostbyaddr($_SERVER['REMOTE_ADDR'])
)
);
Or maybe just remove this line from your code:
Code: Select all
mysql_close();

Hope this helps,
Elijah
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. 

Re: User Defined Tags
Thanks, removing mysql_close(); took care of the problem. Can you explain why?
- Elijah Lofgren
- Power Poster
- Posts: 811
- Joined: Mon Apr 24, 2006 1:01 am
- Location: Deatsville, AL
Re: User Defined Tags
I'm guessing that since CMSMS was already connected to the same database it just reused that connection automatically. So when you called mysql_close(); it closed CMSMS's connection, thus causing problems.argosycms wrote: Thanks, removing mysql_close(); took care of the problem. Can you explain why?

Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. 
