Problem trying insert data in to Mysql Datebase [solved]

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Problem trying insert data in to Mysql Datebase [solved]

Post by andrewvideo »

Hi I am having problems to work out this only half works,


I got working is inserting data in to module_MediaCenter_category, that fine. I want to uplate the id in module_MediaCenter_category.sql and not working. :'( am I missing out something or have I got some code worry.

Can any help and I am new to php and mysql.


Cheers

Andrew


Code: Select all


new_cat_id = $db->GenID(cms_db_prefix() . "MediaCenter_category_seq");
$catview = '0';
$catname = 'Main Videos';
$catalias = 'mainvideos';
$catactive = '1';
$query = "INSERT INTO " . cms_db_prefix() ."module_MediaCenter_category (id, viewed, modified, created, name, alias, active )
VALUES (?, ?, ?, ?, ?, ?, ?)";
# add the Data
$result = $db->Execute($query, array($new_cat_id, $catview , $db->DBTimeStamp(time()), $db->DBTimeStamp(time()),$catname,$catalias,$catactive));




Last edited by andrewvideo on Sat May 21, 2011 9:45 am, edited 2 times in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Problem trying insert data in to Mysql Datebase

Post by calguy1000 »

After a query you can echo:
$db->sql --- to get the exact query that was given to mysql
$db->ErrorMsg() -- to get the error message that mysql returned.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Problem trying insert data in to Mysql Datebase

Post by andrewvideo »

I dint get in any errors

echo $db->sql; gave me

Code: Select all

INSERT INTO cms_module_MediaCenter_category (id, viewed, modified, created, name, alias, active ) VALUES (24, '0', '\'2011-05-21 01:48:04\'', '\'2011-05-21 01:48:04\'', 'Main Videos', 'mainvideos', '1')
and $db->ErrorMsg() return noting. I am really lost now.

The data is going in 'cms_module_MediaCenter_category' fine, just not cms_module_MediaCenter_category.sql. should be adding a id number there and not.

I hope I make sence.

Cheers

Andrew
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Problem trying insert data in to Mysql Datebase

Post by Jos »

The line

Code: Select all

new_cat_id = $db->GenID(cms_db_prefix() . "MediaCenter_category_seq");
should update your sequence table and give you a new ID at the same time.

Could it be you miss something in the tablename? Should that not be like this?

Code: Select all

new_cat_id = $db->GenID(cms_db_prefix() . "module_MediaCenter_category_seq");
andrewvideo
Forum Members
Forum Members
Posts: 127
Joined: Fri Nov 28, 2008 10:28 pm

Re: Problem trying insert data in to Mysql Datebase

Post by andrewvideo »

OMG! I can't believe it. I spent hours on the is problem and it so simple to fix. I could not find the mistake.

Thank you very much Jos for help. Sometimes I find it hard to spot things like that, I have Dyslexia.

Cheers


Andrew
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Problem trying insert data in to Mysql Datebase [solved

Post by Jos »

no problem... I guess we all have these kind of mistakes we never are able to notice ourselves :D
Post Reply

Return to “Developers Discussion”